Because I am working with legacy tables, I wrote my own Auth_Adapter, named User_Auth_Adapter_DbTable. I have a module user and I want to have this class there.
However, I have no idea where to actually put the file and how to name it so the Zend autoloader can find it. I have googled for more than an hour and did not find a hint, so I put it under /application/modules/user/controller/Auth/Adapter/DbTable.php, because it is used by the controller there. But it is not found.
Can you share some code from adapter? I think logically it must be in models folder. And the name of this class should follow Zend Framework naming conventions. So if you will put it to models/user/auth/adapter/DbTable.php class should be named as Model_User_Auth_Adapter_DbTable
I think you need to define service folder.
Define folder named service path /application/modules/user/service/ (Recomended Zend-project structure), put there your adapter DbTable.php (class name must bee Application_Modules_User_Service_DbTable). You can call this class:
$adapter = new Application_Modules_User_Service_DbTable();
Related
I am trying to extend the DbManager in order to set my own table names for $itemTable, $itemChildTable and $assignmentTable.
Sadly I don't know how to add my new folder of myComponents to the namespace, and I don't want to create it under the same folder as the other in case I need to upgrade the framework.
Anyone added an other folder for namespaces to Yii2.0 ?
It doesn't need to be in the same namespace, as long as you correctly specify the class namespace "path" when you update the configuration.
If you have added the new folder under the common part, the class path for your DbManager would be common\myComponents\DbManager. As said, if then correctly update the config, you should be set.
At this moment i am having a problem, my controller called userspace, his model called userspace and view is userspace too, logically everything is fine, but just a plain example when you open this 3 files sometimes it's hard to understand where is model and where is controller if not to start reading the code.
So i ask for advises or examples of coding standarts :)
I normally tend to use singular/plural to distinguish from model/controller.
That being said, this is how I do things:
Model
File name: app/classes/model/userspace.php
Class name: Model_Userspace
This is also FuelPHP's naming convention (at least for Models). This way you don't have to specify the table name on the model, like so:
protected static $_table_name = 'userspaces';
because FuelPHP will look for the plural version of your model name.
Controller
File name: app/classes/controller/userspaces.php
Class name: Controller_Userspaces
Views
Folder: app/views/userspaces/
This keeps things organized per controller name. For each controller action, a view should be created. So, if you have a create and edit action in your Controller_Userspaces, you will create the following files:
Create: app/views/userspaces/create.php
Edit: app/views/userspaces/edit.php
Forging the views should be a matter of calling:
View::forge('userspaces/create');
View::forge('userspaces/edit');
You should check the FuelPHP ORM documentation for more information.
UserSpaceView(view/gui) / UseSpaceViewController(controller) / UserSpaceModel(model)
We namespace everything, instead of using underscores, so
\Controller\Userspace
\Model\Userspace
\View\Userspace
and
\Module\Controller\Userspace
\Module\Model\Userspace
\Module\View\Userspace
For models you can do directly, for controllers you need to change the controller prefix in the config (from "Controller_" to "Controller\"), which means you have to namespace ALL your controllers from this point.
This is going to be the standard for Fuel v2, it will not support "underscore to directory separator" mapping anymore.
Note that \View maps to ./classes/view, which are Viewmodel classes, not View files!
I'm trying to get Yii to autoload a component that doesn't follow Yii conventions. The library in question is Stripe which I moved into the Components folder. I was able to get it to autoload the main Stripe file no problem by modifying my config like this:
'import'=>array(
'application.models.*',
'application.components.*',
'application.components.stripe.*',
),
The directory structure looks like:
Components
----------
|
----> Stripe
|
----> Stripe.php (Class Name = "Stripe")
----> Customer.php (Class Name = "Stripe_Customer")
----> Charge.php (Class Name = "Stripe_Charge")
----> etc.
It has no problem recognizing the Stripe class, but can't find the Stripe_* named classes. Is there a way to get Yii to recognize this pattern or am I stuck with manual require statements in my controller? Would it work if I renamed all the files to be what their class name is?
Yes, renaming the file to the class name would help. Otherwise you have to require the classes by yourself.
You could also create your own autoloader and register it with: Yii::registerAutoloader(array("AutoloderClass", "methodName"), $append);.
First parameter is actually a php callback, i used class and method notation, can be function as well. This actually calls spl_autoload_register in order depending on second param - before or after Yii autoloader. Autoloader should be registered in index.php just before $app->run().
Some sample autoloader (for zend framework) can be found here:
http://www.yiiframework.com/extension/zendautoloader
I have an enCrypt and deCrypt class which I want to use in my whole Zend Framework project without having to declare it on every need, but just once. Where should this be done? Thank you for any help...
Zend Framework is quite flexible in implementing things.
You could create an instance in a bootstrap file and save it to the registry; whenever you need to call the class just get it from registry?
You could have every controller extend Zend_Controller_Action and put the two functions into this class (only ideal if you're calling the classes from the controller).
Or, what I did, was make my functions static, register my own library (in your application config.ini file, enter the line: autoloaderNamespaces[] = "MyPrefix_", then create a folder in the library folder called MyPrefix) and drop my class in there. When I need it I call $encryptedString = MyPrefix_Crypt::encrypt($string); and $string = MyPrefix_Crypt::decrypt($encryptedString);
Hope this helps :)
I am playing with the build settings in my build.properties file for propel (version 1.5.4) but don't get it right.
Example: Table News should have
class Model_News in ./Model/News.php
class Model_Base_News in ./Model/Base/News.php
My main problems:
propel adds the project name as a folder between Model and News.php like: /Model/project/News.php
propel adds the propel.classPrefix to the file, too. So propel.classPrefix = Model_ builds class Model_News inside /Model/project/Model_News.php
aaaaaaaaaaaahhhh :-(
I don't think you can customize the paths to this form by only using build.properties. You probably need to overload the OMBuilder::getClassFilePath() (used by PropelOMTask::build()) function in your own custom build classes. Unfortunately you cannot just override the OMBuilder class, but you must create subclasses for all *Builder classes.
Personally, I'd stick with the Propel conventions and just use the Propel autoloader for Propel classes. Not as clean as your intended solution, perhaps, but I'd not reject an ORM just on the basis of its internal file naming.