草庐IT

php - 这个 MVC Controller 代码是否需要重构?

我正在为MVC应用程序(Kohana/PHP)编写一个CSV/Excel-->MySQL导入管理器。我有一个名为“ImportManager”的Controller,它有一个名为“index”(默认)的Action,它在网格中显示所有有效的.csv和.xls位于特定目录中并准备好导入的文件。然后用户可以选择他想要导入的文件。但是,由于.csv文件导入到一个数据库表和.xls文件导入到多个数据库表,我需要处理这个抽象。因此,我创建了一个名为SmartImportFile的helper类,我将每个文件发送到该类,.csv或.xls并且然后我得到然后要求这个“智能”对象将该文件中的工作表(是

php - Zend 框架 : How to give specific order to javascript files and scripts

我在布局中包含以下javascript文件:$this->InlineScript()->appendFile($this->baseUrl('resource/js/jquery.js'));$this->InlineScript()->appendFile($this->baseUrl('resource/js/main/login.js'));$this->InlineScript()->offsetSetFile(3,$this->baseUrl('resource/js/core.js'));我在View文件中有以下脚本:InlineScript()->captureStar

PHP 变量范围和 "foreach"

我的应用程序正在构建PDF文档。它使用脚本来生成每个页面的HTML。PDF生成类是“Production”,页面类是“Page”。classProduction{private$_pages;//anarrayof"Page"objectsthatthedocumentiscomposedofpublicgetPages(){return$this->_pages;}publicrender(){foreach($this->_pagesas$page){$pageHtml=$page->getHtml($this);//Pagetakesapointertoproductiontoa

php - 对象集合类与否

我正在尝试决定是为我的应用程序/数据库中的每种内容类型创建许多类,还是只坚持使用过程代码。版本1:为每个对象集合创建一个类:classApp{protected$user_collection;functiongetUserCollection(){if(!isset($this->user_collection)$this->user_collection=newUserCollection($this);return$this->user_collection;}//...}classUserCollection{function__construct(App$app){$this

php - 如何使 Codeigniter 中的分页类与 AJAX 一起工作?

我有一个通过AJAX加载的表格,分页也通过AJAX加载。该表包含我网站上所有用户的列表,一次限制为30个。这就是我从Controller返回对JavaScript的响应的方式:$users=$this->users_m->get_users($type,$offset);$num_rows=$this->users_m->user_stats($type);$config['per_page']=30;$config['num_links']=5;$config['total_rows']=$num_rows[0];$this->pagination->initialize($conf

php - 从函数调用 PHP 对象方法

我有创建类对象的protected函数protectedfunctionx(){$obj=newclassx();}现在我需要从不同的函数访问类对象的方法(我不想再次初始化)。protectedfunctiony(){$objmethod=$obj->methodx();}我怎样才能完成它?哦,这两个函数都存在于同一个类中,比如'classz{}'错误信息是Fatalerror:Calltoamemberfunctionget_verification()onanon-objectin 最佳答案 将$obj,classx的实例存储在

php - 在 PHP 中使用 "this"和 "self"

Use$thistorefertothecurrentobject.Useselftorefertothecurrentclass.Inotherwords,use$this->memberfornon-staticmembers,useself::$memberforstaticmembers.http://board.phpbuilder.com/showthread.php?10354489-RESOLVED-php-class-quot-this-quot-or-quot-self-quot-keywordclassDemo{privatestatic$name;private

php - 克隆 CodeIgniter 的数据库对象

我正在为CodeIgniter(linktoproject)开发一个子查询库,它通过返回数据库对象来工作,您可以使用这些对象来代替普通的$this->db对象。最初,我每次都在创建新的数据库对象:$this->CI=&get_instance();$db=$this->CI->load->database('',true);但是我随后意识到(或者更确切地说有人向我指出)这每次都会建立一个新的数据库连接!所以我决定尝试克隆对象而不是创建新对象。我将代码更新为如下所示(linktofullcode):classSubquery{var$CI,$db;function__construct(

php - 创建模块 prestashop 1.5

我在PrestaShop1.5中创建了一个新模块mau文件mymodule.php内容name='mymodule';    $this->tab='Test';    $this->version=1.0;    $this->author='FirstnameLastname';    $this->need_instance=0;     parent::__construct();     $this->displayName=$this->l('Mymodule');    $this->description=$this->l('Descriptionofmymodule.

php - 流体接口(interface)如何返回 $this 和值?

我对OOP比较陌生,所以浏览SimpleHTMLDOM的文档时我想知道它的方法如何使用方法链和返回值/对象的常规行为。例如我可以这样做:$html=newsimple_html_dom();$html->find('something');//Returnsobjectorarrayofobjects但我也可以:$html->find('something')->find('something_else');如果我正确理解方法链接,这意味着find()返回$this即它本身。此外,我的理解是使用方法链接返回$this,之后使用getter方法实际返回一个您可以使用/想要的值。例如:$o