How to install Yii extension when 'log'>'routes' is an associative array? - yii

I ran into this while trying to install several Yii extensions.
E.g.
http://www.yiiframework.com/extension/yii-debug-toolbar/
or
http://www.yiiframework.com/extension/yiidebugtb/
Instructions say to get this in the components part of config/main.php:
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'ext.yii-debug-toolbar.YiiDebugToolbarRoute',
'ipFilters'=>array('127.0.0.1','192.168.1.215'),
),
),
),
However, my log > routes is an associative array.
This is what mine looks like:
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
'web'=>array(
'class'=>'CWebLogRoute',
'levels'=>'error, warning',
'categories'=>'system.db.*,hhinfo',
'showInFireBug'=>true
),
'file'=>array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning, watch',
'categories'=>'system.*',
),
'profile'=>array(
'class' => 'CProfileLogRoute',
'report'=>'summary',
),
),
),
Does anyone know how I can install the extensions?

To configure yii debug toolbar you need to add this in your log config:
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning', //'trace, info, error, warning, vardump'
),
array(
'class'=>'ext.yii-debug-toolbar.YiiDebugToolbarRoute',
'ipFilters'=>array('127.0.0.1','::1','localhost'),
),
.......
Your problem can be the ipFilters because you need to add the correct ip(v4 and v6) and you need to extract yii-debug-toolbar from zip archive folder to extensions folder.

It turns out that combining a non-associative member to the routes array is perfectly fine.
I haven't figured out why http://www.yiiframework.com/extension/yiidebugtb/ isn't working.
But the problem with http://www.yiiframework.com/extension/yii-debug-toolbar/ was that it appeared only on certain pages, and it shows as a small plus sign in the top right corner. I missed it.
I also found that if you're using it locally you don't need an IP address. Just:
'routes'=>array(
array(
'class'=>'ext.yii-debug-toolbar.YiiDebugToolbarRoute',
),
),

Related

Yii CActiveDataProvider Relations

Anyone can enighten me, i am new to Yii. I have 3 tables
projects (id,name,status,created_by)
users (id,name)
project_users (id,project_id,user_id)
The condition is: Show all projects if created by current user or current user is a project member. I have already a working code for this.
$criteria=new CDbCriteria;
$criteria->join = ' LEFT JOIN project_users pu ON pu.project_id=t.id';
$criteria->addCondition('created_by='.Yii::app()->user->id.' OR pu.user_id='.Yii::app()->user->id);
$criteria->distinct = true;
$dataProvider=new CActiveDataProvider('Project',
array(
'pagination'=>array('pageSize'=>15),
'criteria'=> $criteria
)
);
But, id like to learn how can i get same result using "WITH" (relational AR query in Yii). I already tried but all failed. Please help thanks.
the relation on Project model file
projectUsers' => array(self::HAS_MANY, 'ProjectUsers', array('id'=>'project_id')),
$dataprovider should be
$dataProvider=new CActiveDataProvider('Project',
array(
'pagination'=>array('pageSize'=>15),
'criteria'=>array(
'with'=>array(
'projectUsers' => array('alias' => 'pu')
),
'condition' => 't.created_by='.Yii::app()->user->id.' OR pu.user_id='.Yii::app()->user->id,
'distinct'=>true,
'together'=>true,
),
)
);
Check out my picture. The criteria is more powerful than that, but you can understand the basically how to use
Small tip: If everything is new with you, just enable Yii log to see what the query is produced eventually, then you can troubleshoot the problem by yourself.

ZF2 Modules in Subfolders

due to a large project which will be realised in ZF2, I came across the following problem and I seem to misunderstand the handling of namepaces.
The project will have a lot of modules of similar groups. I will have 4 groups (A, B, C, D) and all modules in group A will deal with input for example. In order to make sure, that we do not end up with a folder containing 200 modules, we want to group the ones that belong together for reasons of cleanliness.
So basically we wish for the following structure:
/config
/module
/MainApplication <- accesses all modules
/groupA
/Module1
/Module2
/groupB
/Module3
/Module4
...
I already adjusted the namespace to groupA\Module1, adjusted the routes accordingly and all the paths seem to be correct and yet I get errors saying that for example the template files cannot be accessed.
Can you give me a hint what you would have to pay attention to when you move a model from /modules/module1 to /modules/subfolder/module1.
What I tried
Changed all namespaces to: -------------------------------------------
groupa\module1[\Controller];
/config/application.php: ---------------------------------------------
...
'modules' => array(
'groupa\module1',
),
...
/module/groupa/Module.php: -------------------------------------------
...
'route' => '/',
'defaults' => array(
'controller' => 'groupa\module1\Controller\Index',
'action' => 'index',
),
...
'controllers' => array(
'invokables' => array(
'groupa\module1\Controller\Index' => 'groupa\module1\Controller\IndexController'
Currently, the module is not supposed to do much. Just showing the index.phtml template. The error I get is the following:
Fatal error: Uncaught exception 'Zend\View\Exception\RuntimeException' with message 'Zend\View\Renderer\PhpRenderer::render: Unable to render template "groupa/index/index";
resolver could not resolve to a file' in /Users/xxx/Sites/zf2helloworld/vendor/Zend/View/Renderer/PhpRenderer.php:461
Stack trace:
#0 /Users/xxx/Sites/zf2helloworld/vendor/Zend/View/View.php(203): Zend\View\Renderer\PhpRenderer->render(Object(Zend\View\Model\ViewModel))
#1 /Users/xxx/Sites/zf2helloworld/vendor/Zend/View/View.php(231): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#2 /Users/xxx/Sites/zf2helloworld/vendor/Zend/View/View.php(196): Zend\View\View->renderChildren(Object(Zend\View\Model\ViewModel))
#3 /Users/xxx/Sites/zf2helloworld/vendor/Zend/Mvc/View/Http/DefaultRenderingStrategy.php(128): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#4 [internal function]: Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent))
#5 /Users/xxx/Sites/zf2helloworld/vendor/Zend/EventManager/Ev in /Users/xxx/Sites/zf2helloworld/vendor/Zend/View/Renderer/PhpRenderer.php on line 461
Am I missing the obvious? Why can the template not be found? I echoed back the 'template_path_stack' and it seems to be correct:
/Users/xxx/Sites/zf2helloworld/module/groupa/module1/view
I am aware of the reusability of modules and such. We would still love to group modules that belong together into the same folder and preferably access them via the proper URL (groupname/module).
Thank you for your time!
First of all, as per PSR-0 standard your classnames must have the following structure: \<Vendor Name>\(<Namespace>\)*<Class Name>.
Meaning that your module name should be <Vendor Name>\<Module\Name>
As for template name, by default FQCN of controller is converted to template like this First namespace/controller class name/controller action name
Meaning your Groupa\Module1\Controller\IndexController controller will give you template name groupa/index/index(and not groupa/module1/index/index as you might expect) which will be resolved to file groupa/index/index.phtml in paths defined in template_path_stack
This is default behaviour and it cannot be changed without backwards compatibility break. To mitigate that since zf2.3 there is new setting that will allow you to use modules the way you want.
It is controller_map under view_manager config section.
How to use that you can read here:
https://github.com/zendframework/zf2/pull/5670
'view_manager' => array(
'controller_map' => array(
// Groupa\Module1\Controller\IndexController -> groupa\module1\index\index
// -> module/Groupa/Module1/view/groupa/module1/index/index.phtml
'Groupa\Module1' => true,
),
);

why are two records getting added to the database when I only call my typo3 repository->add method once?

here is the code that runs and that results in two sentmessage objects getting added to the table:
$sentmessage = null;
//add entry into sent message table Tx_BpsMessagecentre_Domain_Model_Sentmessage
$sentmessage = $this->objectManager->create('Tx_BpsMessagecentre_Domain_Model_Sentmessage');
//now just fill in the object
$sentmessage->setBpsmessageid($bPSMessage->getUid());
$sentmessage->setBody($bPSMessage->getBody());
$sentmessage->setSubject($bPSMessage->getSubject());
$sentmessage->setCouponlist($bPSMessage->getCouponlist());
$sentmessage->setHallname($bPSMessage->getHall()->getHall());
$sentmessage->setHalladdress($bPSMessage->getHall()->getAddress());
$sentmessage->setHallurl($bPSMessage->getHall()->getUrl());
$sentmessage->setBanner($bPSMessage->getBanner());
$this->sentmessageRepository->add($sentmessage);
$this->objectManager->get('Tx_Extbase_Persistence_Manager')->persistAll();
die; //if I take out this die and the persist call above I still get two records added
I am using typo3 v 4.5.32 with extbase 1.3.
The sentmessage object is one I had to create manually - ie without extension builder, so there might be some misconfiguration in the TCA somewhere but I have no idea what would cause this.
Thanks
PS: a piece of my ext_localconf.php showing some of my plugins
Tx_Extbase_Utility_Extension::configurePlugin(
$_EXTKEY,
'Bpsmonthly',
array(
'BPSMessage' => 'cronMonthlys'
),
// non-cacheable actions
array(
'BPSMessage' => 'create, update, delete',
)
);
Tx_Extbase_Utility_Extension::configurePlugin(
$_EXTKEY,
'Bpsbirthdays',
array(
'BPSMessage' => 'cronBirthdays'
),
// non-cacheable actions
array(
'BPSMessage' => 'create, update, delete',
)
);
Tx_Extbase_Utility_Extension::configurePlugin(
$_EXTKEY,
'BpsAnnuals',
array(
'BPSMessage' => 'cronAnnuals'
),
// non-cacheable actions
array(
'BPSMessage' => 'create, update, delete',
)
);
Ok, found the bug, it was actually caused by my debug code that spit some url out to the page, the url got resolved by the browser to hit the action again (probably a url in an img tag) and boom. so the bug only exists while debugging. I love programming.
Is there a way to delete my dumbest questions from stackoverflow?
most probably you have the two plugins from the same extension in your website - therefore everything is processed twice.
Maybe persisting your changes takes a loooooong time (e.g., >30 sec). In such cases, I experienced that under some conditions the browser posts again (!) the query, resulting in what you describe.
As I experienced the same behaviour, but under other circumstances, I'm adding my case as an answer here, maybe it helps someone.
If you're working with multiple records in the same form (model having child records) and they all are not persisted, make sure to not set the parent record on the child records.
This will lead to the multiple-rows behaviour:
$foo = ObjectManager->get('Foo\\Bar\\Domain\\Model\\Foo');
$bar = ObjectManager->get('Foo\\Bar\\Domain\\Model\\Bar');
$bar->setFoo($foo); // <-- Should not be done
$foo->add($bar);

Yii CMultiFileUpload select multiple files at once doesnt work

i want to select multiple files at once, but only ONE File always shows up in the MultiFile-list Div container with the possibility to delete it. But i want to shop up all the files i selected.
What am i doing wrong?
$this->widget('CMultiFileUpload', array(
'model' => $gallery,
'name' => 'attachments',
'accept' => 'jpg|png',
'denied' => 'Only doc,docx,pdf and txt are allowed',
'max' => 100,
'duplicate' => 'Already Selected',
'options'=>array(
),
'htmlOptions' => array('multiple' => 'multiple', 'size' => 25)
)
);
CMultiFileUpload is based on jQuery Multiple File Upload Plugin ($.MultiFile) . On it's site we can read:
What this isn't
This plugin will not create a dialog that allows the user to select multiple files at once. That simply cannot be done via javascript. If that's what you need, you should consider using HTML5's multiple="multiple" attribute or one of the many other flash based file upload solutions (eg.: SWFupload, uploadify and others)
So probably the built in widget isn't what you are looking for. Xupload yii extension, on the other hand might be what you are looking for.

Magento API - Several methods do not work

I've got the following problem. I built a PHP file, which reads categories from a file, to impor tthem into Magento. I am able to read the file, no problem. The connection via NuSOAP to the Magento API works aswell. I can get the SessionID and I am able to get data, like Information for a category, also its possible to delete categories.
But, whenever I try to create or update anything, it throws an error. The rights for the user are ok aswell. For example, when I create a category, I add the usual data to the call:
$proxy->call(
$sessionId,
'category.create',
$rootCategory, array(
'name' => "TEST",
'is_active' => '1',
'page_layout' => 'two_columns_right',
'description' => "TEST",
'meta_title' => "TEST",
'meta_description' => '',
'meta_keywords' => "TEST",
'include_in_menu' => '0',
'display_mode' => 'PRODUCTS',
'available_sort_by' => 'price',
'default_sort_by' => 'price',
'is_anchor' => '0'
)
);
All the time, it says:
(
[faultcode] => 102
[faultstring] => Category not exists. )
Which is not true. The $rootCategory is definatly a category, which is existing. I tried all other categories, I tried to add a 'path' to the info, I tried to use less information (only the neccesary stuff), I tried to read existing categories to get their IDs, NOTHING works. It always throws this faultcode.
Same happens, when I try to update a category, or create /update a product. Deleting is no problem at all.
Do you see the problem?
i just compared your NON working exemple and i found this while comparing it with another exemple i has ( i do not pretent to be expert ) ..
but seems like your $new_category, array(blahblha) ...
should be INSIDE an array according to the exemple i already have
like this array($new_category,array(blahblah) ...
this is the mains difference i just saw ..
here is the EXEMPLE i just pulled out of the web ... Adapt to your needs..
$proxy->call(
$sessionId,
'category.create',
array(
3,
array(
'name'=>'New openerp',
'is_active'=>1,
'include_in_menu'=>2,
'available_sort_by'=>'position',
'default_sort_by'=>'position')) );
Have you tried specifying the category_id key in your $rootCategory within the call:
$selectedCategory['category_id'],
array('name'=>'New Category Through Soap')
)
Reference: http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_category