A lightweight Yii application embedded into OpenCart.
Yii::app()
or Yii::foobar
Yii::app()->registry
The following Yii components are pre-configured to work in your OpenCart:
Yii::app()->assetManager
-
CAssetManager
Yii::app()->clientScript
-
CClientScript
Yii::app()->controller
-
CController
Yii::app()->db
-
CDbConnection
Yii::app()->errorHandler
-
CErrorHandler
Yii::app()->session
-
CHttpSession
Yii::app()->urlManager
-
CUrlManager
Yii::app()->messages
-
CMessageSource
Download the latest release or
development version and uncompress the upload
folder into your opencart installation.
The application has been tested with the following software versions, however should work with any minor revision change:
system
folder. The yii.php
file should be in
system/yii/framework/yii.php
.
Copy the Yii config files in catalog/yiiembed/config/main-dist.php
and
admin/yiiembed/config/main-dist.php
to main.php
.
If you have installed vQmod then no further installation is required.
system/startup.php
BEFORE the closing php tag ?>
require_once(DIR_SYSTEM . 'yiiembed/yiiembed.php');
system/engine/front.php
AFTER $this->registry = $registry;
Yii::createApplication('OcWebApplication', array('registry' => $registry, 'front' => $this));
system/library/response.php
BEFORE echo $output;
Yii::app()->clientScript->render($output);
catalog/controller/error/not_found.php
and admin/controller/error/not_found.php
AFTER public function index() {
Yii::app()->runController();
admin/controller/user/user_permission.php
AFTER $this->data['permissions'] = array();
$this->data['permissions'] = array_merge($this->data['permissions'], Yii::app()->getPermissionList());
system/library/user.php
BEFORE return in_array($value, $this->permission[$key]);
if (in_array(implode('/', array_slice(explode('/', $value), 0, 1)), $this->permission[$key])) return true;
Edit the Yii config files in catalog/yiiembed/config/main.php
and
admin/yiiembed/config/main.php
(you should have copied these from
main-dist.php
during the installation).
Add Yii constants to your OpenCart config.php, defaults shown below:
define('YII_DEBUG', false); // set to true for fancy error messages define('YII_TRACE_LEVEL', 0); define('YII_ENABLE_EXCEPTION_HANDLER', true); define('YII_ENABLE_ERROR_HANDLER', true);
Navigate to Admin > System > Users > User Groups, then edit the Top Administrator. Select all the permissions for all the Yii pages. Repeat for any other User Groups that need to access these pages.
The files in catalog/yiiembed
and
admin/yiiembed
are intended to be modified by you. When upgrading please ensure you do not overwrite your modified yiiembed applications with the default applications.
The files in
system/yiiembed
are intended to be in-sync with this project. Please avoid changing them, you can extend them if you require modifications.
It is probably because your JavaScript from Yii is outputting too early. The <title>
tag is too high on the page. Yii outputs all the CSS/JS right before the <title>
tag, so try moving it below your other CSS/JS files.
jQuery in chrome treats inline elements as hidden. In the default opencart stylesheet on line 46, there is CSS to make forms display inline. You can remove this, or add 'htmlOptions' => array('style'=>'display:block;')
to your form.
If you get an error like Customer::__construct() Missing argument 1 for Customer::__construct()
, it is because there is already a Customer class built into OpenCart. You should name your models with a prefix, for example OcCustomer
.
Find and save a record (in this example we use a Customer):
$customer_id = 123; $customer = OcCustomer::model()->findByPk($customer_id); if ($customer) { $customer->firstname = 'Foo'; $customer->lastname = 'Bar'; $customer->save(); }
Render Yii partial views:
Yii::app()->controller->renderPartial('/site/_partial');
Render Yii widgets:
Yii::app()->controller->widget('zii.widgets.CDetailView', array( 'data' => array('hello' => 'world'), ));
Run OpenCart controller:
Yii::app()->runOcController('common/home');
Get OpenCart controller output:
echo Yii::app()->getOcControllerOutput('common/header'); echo 'hello world'; echo Yii::app()->getOcControllerOutput('common/footer');
Output OpenCart language label:
Yii::t('module/bestseller', 'heading_title');
You can use Yii's awesome code generator from your OpenCart admin, just like you can in any other Yii app. Simply browse to your admin
admin/index.php?route=gii
.
To tune the Gii configuration or security access edit admin/yiiembed/config/main.php
.
Use the PrefixModel Generator to generate all your models in one action.
Select the Code Template yiiembed
to generate models the same as ours.
Use the ModelDoc Generator to replace the phpdoc blocks in your models.
All the default Gii Generators including Controller Generator, Crud Generator, Form Generator, Model Generator and Module Generator are also available.