Yii solutions for "my big e-commerce service"

sorry if it is a long text, I’ve divided it to 3 problems, so you may just read one section or all of them to help a newbie. thank you very much :wub:

Hello. I’m coming from modular programming and embedded scripts in html world. I’m completely familiar wit OOP and recently with MVC. my next project is a service for building e-shops for “traditional business mans”, guys with no computer skill. I’m here to ask you: “what is the best solutions around Yii for my Problems?”. here we have problems list, you may help me on any of them, please. thank you:

Problem A. Using themes, I want a drag & drop layout designer to enable my traditional guys to change their e-shop layout without even a line of coding. I’ll define some WIDGETs for them, for example: ‘product list widget’ that will get category and count of products to show in a thumb & title format. also I want some 'area’s on the pages (home, basket, payment, category…) so user can add, sort, remove widgets in that predefined area, different from theme to theme. to be clear, something similar to concepts described on this page: crowdfavorite.com/wordpress/carrington-build

how to do? yes it’s a sophisticated thing to answer, just the idea, based on Yii. I don’t know, I have to display view files in layout editor then after changes save that file again, I have to use databases and define widgets for each page o area, I have to…? yet a newbie here to find solution with Yii. :unsure:

Problem B. We have a BOSS who is manager of service, she can create a new shop for a customer or maybe remove other one. let say boss has a new customer, she wants to create a new shop with default setting. what is the best solution? my options: 1) all customers use the same ‘system’ so for a new customer we just create a new database. 2) like 1, but we use table prefix for different customers, ‘cust226_tbl_products,cust227_tbl_product…’. 3) just create a new directory structure for any user and also a new database!

so what is the best? in Yii is it possible to switch between databases in run time? what about backup cron jobs? :mellow:

Problem C. Plug-in system! yes. I want to have some available plug-ins, then one of my shop administrators install (actually add/buy) a plug-in that make him able to show some banners in slide-show manner on home page. after install we actually grant access to that plug-in, not a real install.

plug-ins have a special ‘panel’ in shop admin area and maybe some navigation items in different sections too. even we want plug-in related widgets to be available after installing that plug-in, so admin can add widget in home page on elsewhere. so what to do?! ???

thank you :)

Really no idea?!

:huh: :(

challenge A,C i will leave for somebody else to answer since i have not much clue on these topics right now…

challenge B: My recommendation: create databases for new customers but use the same system. You could use different database configuration for different domains… just map a domain to a db config and then load it conditionally…

Thank you TeamTPG. yes this is a good way to do it.

A & C… no solution yet.

Questions A & C are really architecture questions, not Yii questions. Answering the Yii parts of these questions probably won’t help you much, but here goes.

a) Check out Flexica CMS. It is based on Yii and does similar stuff. You my be able to use it as a reference, or you might even be able to build your app on top of it.

c) You can make each of your "plugins" yii modules. Modules can have their own widgets and so forth, and they can easily be loaded or unloaded from the application configuration. How you work the interface to include or not include widgets on a given page will probably related to what you decide to do about question A

Really thank you MadSkills, big help :)

one question: I have a component with ‘onInit’ event, but I don’t know what I have to use for ‘handler’. I mean… what is event handler (type)? a method of some class? f controllers? waht can be? please… :huh:

Event handlers are methods or functions that do something outside of normal application flow when a certain event is raised. If you need to do something like register scripts or connect to a database, onInit might be a good place to do these things, since the event handler you assign will be called when the component is initializing, before it does anything.

More info: http://www.yiiframework.com/wiki/44/behaviors-events

any class in yii is ready to have events? or just components? then what about event handler?

I’ve looked at documents and cook book but sorry… I cant get it completely

is it possible to describe it with a real world code example? a very simple one… thank you ???

Anything that calls raiseEvent() can have a listener attached. You can do things like attach events to beforeSave and afterSave with CActiveRecord objects or its children. You can also look at onInit in widgets, just to name a few. What are you trying to do exactly? I’d like to give you an example that relates to your project.

thank you. ok I can now understand it :rolleyes:

I have some components (let say ‘plugins’), I want allow anyone to write a component for system. this components should act in various areas of system, in menu, forms… so I want to have some events in my controllers and models in the way that any component has ability to attach it’s event handlers and affect on process.

Yii doesn’t have a global event dispatcher. It means that a new event listener can’t be attached to e.g. a model without touching application’s code. You probably have to implement an application component, that listens to model/controller events, and raises its own events. Since applicaton components are available globally, plugins can attach themselves to the events of this “globalEvents” component.

oh flexica website is inactive now… any other resource for downloading this system?

phtamas @ yeah? thank you :) but how “implement an application component, that listens to model/controller events” if there is no event in controller/model side? does it has something to do with checking URLs method param to detect current action? then what about models? :unsure:

Model events should be raised from the model object, but you need something in the global scope that

makes plugins able to register themselves to this events:

class MyModel extends CActiveRecord


	public function init()


		$this->attachEventHandler('onMyModelEvent', array(Yii::app()->globalEvents, 'onMyGlobalModelEvent');


	public function onMyModelEvent()


		$this->raiseEvent('onMyModelEvent', new CModelEvent($this));



class GlobalEvents extends CApplicationComponent


	public function onMyGlobalModelEvent($event)


		$this->raiseEvent('onMyGlobalModelEvent', $event);



class MyPlugin extends CApplicationComponent // may extend other class depending on your plugin design


	public function init()


		Yii::app()->globalEvents->attachEventHandler('onMyGlobalModelEvent', array($this, 'handleMyGlobalModelEvent');



	public function handleMyGlobalModelEvent($event)


		// handle event



very thanks for your time.

good example :rolleyes:

I’ll try this method :)

My project was sleeping till now.

about plugin system: Admin of system can install or remove plugins, as well as disabling or enabling them. I have a basic idea to build plugin system.

using phtamas solution, I have a ‘plugin’ folder, any plugin is a single file named equal to plugin class name. every plugin has an init() method. In the system startup I’ll check db for installed and active plugin names, then with yiiBase::createComponent() initialize them. in the init() method I can attach events to globalEvent component… good? any better idea… ???

Have you progressed on this?

I’m looking for a plugin system too!