Yii

路径重写,适用于laravel,yii

前提是你 提交于 2019-12-26 01:02:09
<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On #直接访问域名而没有参数的情况下直接重写到入口文件 RewriteCond %{REQUEST_URI} ^.?$ RewriteRule ^(.*)$ /public/index.php [L] #如果public目录下存在请求目录或文件,重写请求到实际目录 RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -d [OR] RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f RewriteRule ^(.*)$ /public/$1 [L] #请求不存在的目录或文件的情况下重写到入口文件 RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ /public/index.php [L] </IfModule> 来源: https://www.cnblogs.com/mengxiaotian/p/5572029.html

Yii 事件和行为

半腔热情 提交于 2019-12-25 19:57:09
一:事件 事件可以将自定义代码“注入”到现有代码中的特定执行点。 附加自定义代码到某个事件,当这个事件被触发时,这些代码就会自动执行,例如当我们向数据库的一个表中新增数据时,如果你想要在新增数据之前或新增数据之后执行指定的操作的话,这时候我们就可以使用事件来实现 如: 在表对应的模型的init方法中添加: //新增数据之前事件,处理器是对象方法 $this->on(Country::EVENT_BEFORE_INSERT, [$this, 'function_name']); //新增数据之后,处理器是匿名函数 $this->on(Country::EVENT_AFTER_INSERT,function ($event) { echo '新增数据之后'; }); 处理器是对象方法的在模型中新增一个function_name方法,该方法为当指定事件触发时执行 public function function_name($event) { echo '新增数据之前'; } 事件处理器调用yii\base\Component::on() 方法来附加处理器到事件上,该方法的第三个参数的数据,在在事件被触发和处理器被调用时能被处理器使用 可以使用如下方法获取 $event->data 在模型中在事件触发后我们可以使用如下获取对应的表数据 $event->sender

what is the difference between form and chtml in yii

三世轮回 提交于 2019-12-25 18:54:27
问题 confusion between form and chtml i used to form to write form ans submit to database working fine, but for some particular places, according to google search used CHTML instead of form. but when i submitted that form to database CHTML textfield value is not submitting to database here goes my code _Form.php <script language="javascript"> function firstlang(flang,slang,tlang,math,scien,soci) { var sflang=parseInt(flang)+parseInt(slang)+parseInt(tlang)+parseInt(math)+parseInt(scien)+parseInt

give two function in one button in Yii framework

流过昼夜 提交于 2019-12-25 18:27:39
问题 I have a question about Yii framework, i have problem with submit button, i want to given two fungsi save and update in one submit button, can anyone tell me how to set that function on form ? <div class="row buttons"> <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?> </div> i change 'Save' with 'Update' it's still have error Primary key added, how i can create two function update and save in one push button ? public function actionCreate() { $model=new TblUasUts; //

Yii: How to show dynamic bootstrap progress bars on view page

為{幸葍}努か 提交于 2019-12-25 18:17:55
问题 I am a yiibie. I have top 5 ngo's on my view page(top 5 ngo's for each month) and also the top 5 ngo's at the end of the year on the same page. Now i want to show the bootstrap progress bar in front of every ngo. For example if January is the month and it is showing me top 5 ngo's of that month,I want to show a progress bar in front of all those 5 ngo's and I want it for every month. And same thing for the end of the year. Like the 1st ngo progress bar will be 100%, 2nd ngo will have less

Adding a value to the end of a file if it's duplicate in php yii

家住魔仙堡 提交于 2019-12-25 18:14:27
问题 I am trying to handle duplicate filenames. if a user uploads a file name called "file" then another user uploads a file called "file" I want to be able to add a 1 to the new file so it would be now called "1file". I am able to do this but my issue is when someone uploades "file" for a third time it overrides "1file" I need the 1 to increase. I am using The yii framework Here is my function in my controller: function actionIndex(){ //$dir = Yii::getPathOfAlias('application.images'); //$dir is

Yii urlmanager, append language on homepage

痞子三分冷 提交于 2019-12-25 17:44:34
问题 i've wrote the following url rules: '<lang:(it|de|en|fr|es)>' => 'site/index', '<lang:(it|de|en|fr|es)>/search' => 'site/search', '<lang:(it|de|en|fr|es)>/<action:(page|logout)>/*' => 'site/<action>', '<lang:(it|de|en|fr|es)>/<controller:\w+>' => '<controller>/index', '<lang:(it|de|en|fr|es)>/<controller:\w+>/<action:\w+>/*' => '<controller>/<action>', '<lang:(it|de|en|fr|es)>/<module:\w+>/<controller:\w+>/<action:\w+>/*' => '<module>/<controller>/<action>', and they work as i need, but one

Yii urlmanager, append language on homepage

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 17:44:06
问题 i've wrote the following url rules: '<lang:(it|de|en|fr|es)>' => 'site/index', '<lang:(it|de|en|fr|es)>/search' => 'site/search', '<lang:(it|de|en|fr|es)>/<action:(page|logout)>/*' => 'site/<action>', '<lang:(it|de|en|fr|es)>/<controller:\w+>' => '<controller>/index', '<lang:(it|de|en|fr|es)>/<controller:\w+>/<action:\w+>/*' => '<controller>/<action>', '<lang:(it|de|en|fr|es)>/<module:\w+>/<controller:\w+>/<action:\w+>/*' => '<module>/<controller>/<action>', and they work as i need, but one

How to use model object in Yii Controller and View

荒凉一梦 提交于 2019-12-25 17:16:09
问题 I have following method: public function actionIndex() { $companyModel = Company::model()->findAll(); $supplierProductModel = SupplierProduct::model()->findAll(); $this->render('index', array( 'companyData' => $companyModel, 'supplierProductData' => $supplierProductModel, )); } Here I have passed model objects to render function and want to access these objects in view (Active Relational Type) but when I am accessing its in view its showing error: Trying to get property of non-object view

Code to be run twice in Ajax request

醉酒当歌 提交于 2019-12-25 16:44:00
问题 In the if(!$validate) block mail function truly runs once. I'm wondering why In the if($validate) block mail function runs twice !!!??? The problem raise only in Ajax request and in first time that view page loads. after that the if($validate) block runs once, on the other requests if($validate) block truly runs once. public function actionCEmail() { $model = $this->loadModel(Yii::app()->user->id); $model->scenario = 'CEmail'; if(isset($_POST['User'])){ $model->attributes = $_POST['User'];