Yii

How to handle complex form with multiple models and tabular input in yii

老子叫甜甜 提交于 2020-01-23 23:15:30
问题 I've read a lot of documentation about how to handle models and forms in yii and I've found a solution that works for the case that I explain following, but the problem is that the code is complex to write and to maintain, so I'm looking for suggestions. The case is the following: I need to save together two different models and a third model that is a tabular input (more instances of the same model). For instance, I may want to save a Blog post (first model) with the author information

Yii cannot Instantiate controller

北慕城南 提交于 2020-01-23 07:08:28
问题 As I see if we want to instantiate a Model (for example named Post ), we just have to call: $post = new Post(); Now, I also want to instantiate a Controller (for example named Post , and php file for this controller named PostController.php ). So I use this code: $postController = new PostController(); However, I get an error when running this code. I did some searching and found that it should be like the following to instantiate: $postController = Yii::app()->createController('post/index');

Yii cannot Instantiate controller

家住魔仙堡 提交于 2020-01-23 07:08:07
问题 As I see if we want to instantiate a Model (for example named Post ), we just have to call: $post = new Post(); Now, I also want to instantiate a Controller (for example named Post , and php file for this controller named PostController.php ). So I use this code: $postController = new PostController(); However, I get an error when running this code. I did some searching and found that it should be like the following to instantiate: $postController = Yii::app()->createController('post/index');

Change the Row Color Based on the Column value in CGridView

丶灬走出姿态 提交于 2020-01-22 14:18:00
问题 In Yii, CGridView has it's own background color in the row. But what I want to do is highlight particular row based on the value of one of the column. For Instance, I have three column, id, name, status. Now, If the Value of status is Inactive or 0, I should highlight the row with some color. I read the class reference briefly and searched this site as well. But could not find the relevant solution. If some example or some direction toward the right solution, that would be much appreciated.

Creating Yii FormModel objects (CFormModel) dynamically

自作多情 提交于 2020-01-22 08:05:27
问题 I'm working on an application that involves generating forms at a high level of abstraction (it's a CMS app). I want to dynamically create CFormModel objects and set the form fields on-the-fly. I think I can do this by extending CFormModel, and then dynamically creating the class properites that represent the form fields ('attributes' in the Yii lingo). To illustrate, instead of specifying a login form in the following class (defined in a file): // From: http://www.yiiframework.com/doc/guide

Creating Yii FormModel objects (CFormModel) dynamically

社会主义新天地 提交于 2020-01-22 08:05:02
问题 I'm working on an application that involves generating forms at a high level of abstraction (it's a CMS app). I want to dynamically create CFormModel objects and set the form fields on-the-fly. I think I can do this by extending CFormModel, and then dynamically creating the class properites that represent the form fields ('attributes' in the Yii lingo). To illustrate, instead of specifying a login form in the following class (defined in a file): // From: http://www.yiiframework.com/doc/guide

Creating Yii FormModel objects (CFormModel) dynamically

非 Y 不嫁゛ 提交于 2020-01-22 08:04:21
问题 I'm working on an application that involves generating forms at a high level of abstraction (it's a CMS app). I want to dynamically create CFormModel objects and set the form fields on-the-fly. I think I can do this by extending CFormModel, and then dynamically creating the class properites that represent the form fields ('attributes' in the Yii lingo). To illustrate, instead of specifying a login form in the following class (defined in a file): // From: http://www.yiiframework.com/doc/guide

Yii2基本概念之——行为(Behavior)

不打扰是莪最后的温柔 提交于 2020-01-20 12:17:17
使用行为(behavior)可以在不修改现有类的情况下,对类的功能进行扩充。通过将行为绑定到一个类,可以使得类具有行为本身所具有的属性和方法,就好像是类本来就具有的这些属性和功能一样。 好的代码设计,必须要同时满足可复用性、可维护性和可扩展性。 设计原则中有一条非常重要的一条:类应该对扩展开放,对修改关闭(开闭原则)。 改变原有代码往往会带来潜在风险,因此我们尽量减少修改的行为。我们的目标是允许类容易扩展,在不修改现有代码的情况下,就可以搭配新的行为。如果能实现这样的目标,有什么好处呢?这样的设计具有弹性,可以应对改变,可以接收新的功能来应对改变的需求。 Yii的行为就是这样一类对象,当一个对象(继承了Component的)想要扩展功能,又不想改变原有代码时,那么你完全可以用行为去实现这些新功能,然后绑定到该对象上——完全是符合“ 开闭原则 ”的。 Yii的行为都需要继承自 yii\base\Behavior ,而能接受行为绑定从而扩充自身功能的只能是yii\base\Component的子类,只继承BaseObject基类没有继承Component的不能享受此“待遇”。因此,行为是组件才有的功能。行为和事件结合起来使用,还可以定义组件在何种事件进行何种反馈。 因此行为有如下两个作用: 将属性和方法注入到一个component里面,被访问时和别的属性或者方法访问无异( 行为的附加

Linxu下Yii2的POST提交被拒经历

时光毁灭记忆、已成空白 提交于 2020-01-19 13:15:45
早期于对Yii2的使用,浅谈一下自己的经验,在以往的项目中我使用的框架是Yii1,由于Yii2的出现,所以极力的想使用一下它的新特性。 根据不同的WEB服务器,分别给出具体的配置信息,在这我的使用环境Linux系统是CentOS 7.3,Nginx1.12.0安装的PHP版本为PHP 7.0.12: Apache服务器端站点配置 1、修改配置文件:/etc/httpd/conf/httpd.conf中修改两处,若配置虚拟域名另参照其它配置。 DocumentRoot "/data1/vhosts/webapp/app.xxx.com" <Directory "/data1/vhosts/webapp/app. xxx.com"> 2、重定向站点目录,当前目录为 /data1/vhosts/webapp/app. xxx.com,该目录下有文件.htaccess 隐藏文件.htaccess中配置内容: # prevent directory listings Options -Indexes # follow symbolic links Options FollowSymlinks RewriteEngine on RewriteCond %{REQUEST_URI} ^.*$ RewriteRule ^(.*)$ /api/web/$1 Nginx服务器端站点配置 修改配置文件:

YII WEB程序入口(1)

試著忘記壹切 提交于 2020-01-19 02:16:46
来至:http://luchuan.iteye.com/blog/893783 以下分析基于Yii v1.0.6 Yii_PATH表示framework的路径 通常使用Yii框架的index.php程序如下: Php代码 // change the following paths if necessary $yii = dirname( __FILE__ ). '/protected/lib/Yii/framework/yii.php' ; $config = dirname( __FILE__ ). '/protected/config/main.php' ; // remove the following line when in production mode defined( 'YII_DEBUG' ) or define( 'YII_DEBUG' ,true); require_once $yii ; $app = Yii::CreateWebApplication( $config ); $app ->run(); 我们来看一下Yii::CreateWebApplication的过程: Yii其实是YiiBase的helper,因此我们实际查看的是YiiBase::CreateWebApplication Yii_PATH/YiiBase.php: Php代码