草庐IT

this_record

全部标签

php - 如何从 cakephp 中的 $this->Auth->user() 获取 id?

我正在尝试获取已登录用户的用户信息,我正在使用以下函数,$info=$this->Auth->user();//returnsuserinfoasanarray并且能够获取有关用户的所有信息,除了它的id。但我无法从上述数组中获取用户ID。现在我的问题是如何获取上述用户的“id”。注意:我使用的是2.6.7版本的cakephp。任何帮助将不胜感激:) 最佳答案 做这样的事情$id=$this->Auth->user('id'); 关于php-如何从cakephp中的$this->Auth

php - Magento:当我尝试在主页上显示最畅销的产品时,$this->getAddToCartUrl($product) 不起作用

我是Magento的新手,所以我遇到了不同的情况。我找到了一个关于如何在主页上显示最畅销产品的指南,实现它并且一切正常,除了$this->getAddToCartUrl($product)。单击“添加到购物车”后,产品未添加到购物车。这是我的代码:$totalPerPage=($this->show_total)?$this->show_total:4;$counter=1;$visibility=array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,Mage_Catalog_Model_Product_Visibil

php - 将派生字段添加到 Doctrine_Record 子类的最佳方法是什么?

假设我有一个名为“item”的表,其中有一列名为“price”。除了全价之外,我还想获得12个月的价差,即classItemextendsDoctrine_Record{...publicfunctiongetMonthlyPrice(){return$this->price/12;}}现在,假设我想让Item表现得像每月价格只是另一列而不是函数调用,例如,$m=Doctrine_Core::getTable("Item")->find(1);echo$m->price;//prints120echo$m->monthlyPrice;//prints10我的第一直觉是覆盖__get()

php - 找不到类 'Doctrine_Record'

这重新开始here当我收到Class'Classname_model'notfound时。我通过显式调用该类解决了这个问题。然而,它暴露了另一个问题:Fatalerror:Class'Doctrine_Record'notfoundin/../application/models/classname_model.phponline7这是第7行:classClassname_modelextendsDoctrine_Record{现在,我在Doctrine、CodeIgniter和所有OOP/MVC方面都非常陌生。我的Doctrine安装或配置可能有问题吗?

php - 元素 'foo' : This element is not expected. 预期为 ( {http ://www. example.com}foo )

当尝试使用schemaValidate方法根据模式验证PHPDOMDocument对象时,将生成下一个警告:Warning:DOMDocument::schemaValidate():Element'foo':Thiselementisnotexpected.Expectedis({http://www.example.com}foo).inXonlineY它只发生在附加到DOMDocument的元素上。我准备了下一个代码片段和架构,以便任何人都可以立即进行测试:片段:$template='';$DD=newDOMDocument();$DD->loadXML($template);$

php - 为什么使用 array($this ,'function' ) 而不是 $this->function()

我正在检查一个WordPress插件,我在一个类的构造函数中看到了这个函数:add_action('init',array($this,'function_name'));我搜索并发现array($this,'function_name')是一个有效的回调。我不明白的是:为什么要使用这个方法,而不是使用$this->function_name();这是一个示例代码:classHello{function__construct(){add_action('init',array($this,'printHello'));}functionprintHello(){echo'Hello';

php - 在 JsonSerializable 中编码克隆 $this

这个简化的案例会导致PHP段错误(退出127):classDatumimplements\JsonSerializable{publicfunctionjsonSerialize(){returnclone$this;}}echojson_encode(newDatum);最后一行代码导致exit(127)。我无法在当前环境中检索任何堆栈。与此同时,删除clonetoken有效。是否有任何可能的解释为什么会发生这种情况? 最佳答案 此代码导致无限递归。看来PHPJSON模块以这种方式(伪代码)支持JsonSerializable:f

php - Zend 框架 : Setting decorators and labels - should this be done in the view or the form class?

我注意到许多(大多数?)人在使用ZendFramework时会在Form类本身中添加装饰器和标签。classUser_Form_AddextendsZend_Form{publicfunctioninit(){parent::init();$username=newZend_Form_Element_Text('username');$username->setLabel('Username:')->setRequired(true)->addFilter('StringTrim')->addValidator('StringLength',$breakChainOnFailure=f

php - 不在对象上下文中时使用 $this - Laravel 4

我的Contact.php模型中有这两种方法:publicfunctiongetSubscribers($listId){return$this->withTrashed()->where(DB::raw("concat('',email*1)"),'!=',DB::raw('email'))->where('opt_out','0')->select('email')->chunk(1000,function($results)use($listId){$this->subscribeEmails($listId,$results);});}publicfunctionsubscri

php - 销售人员错误 : Element {}item invalid at this location

我正在使用以下代码通过php连接到salesforcerequire_once('SforcePartnerClient.php');require_once('SforceHeaderOptions.php');require_once('SforceMetadataClient.php');$mySforceConnection=newSforcePartnerClient();$mySforceConnection->createConnection("cniRegistration.wsdl");$loginResult=$mySforceConnection->login("