I'm using a third-party extension in Yii and I'd like to know, if it's possible to use the models in the extension.
The extension create a table on my database and the model has a relation rule to my user table. I have added a relation on my user model to the extension's model.
When I do a findAll query, it throws me an error: include(ExtensionModel.php): failed to open stream: No such file or directory.
How do I use models in third-party extensions?
Please have a look at the manual. In the simple case you only need to include this into the 3rd party files:
require_once('path/to/yii.php');
Yii::createWebApplication('path/to/config.php');
I think it would be helpful - see code below:
require_once('path/to/yii.php');
Yii::createWebApplication('path/to/config.php');
Related
I am working with code-igniter in which I want to work with MONGODB at the backend. I used the drivers from https://github.com/huglester/MongoDB-CodeIgniter-Driver ,i.e. added the config (named mongo_db.php) and library files (named Mongo_db.php) as per instructed.
I load this library in the constructor method of my model. Now the issue is that this library class doesn't load and gives me the following error:
"Unable to load the requested class: Mongo_db"
What could be the issue?
I resolved the error.
Turns out, I need to extend my loader class and customize it such that other other "users" libraries can be loaded.
Here's the link to the solution
This is probably very trivial but because I'm new I just don't get it.
I can see the notion of App::uses at the beginning of every file but how does the file know where App is?
There are no includes anywhere and to my understanding there is one autoloader somewhere in lib, does that mean that one autoloader in one file is responsible for loading all the classes (if instantiated)?
I tried reading this part of the manual but still failed to understand how it works.
Also read some material on the spl_autoload_register function itself but no avail.
I'd really appreciate it if someone could help me understand how the files communicate with eachother.
Look at App::load(), it's doc block explains it:
Method to handle the automatic class loading. It will look for each
class' package defined using App::uses() and with this information it
will resolve the package name to a full path to load the class from.
File name for each class should follow the class name. For instance,
if a class is name MyCustomClass the file name should be
MyCustomClass.php.
And look at the frameworks core file lib/Cake/basics.php:
spl_autoload_register(array('App', 'load'));
It registers that method as auto loader.
Good day everyone.
I am frontend developer but I have to make slight adjustments in the backend, built with Zend Framework.
I have a controller CalendarController.php, and wanted to make a relative model, called Calendar. The model was instantiated as
`class Project_Model_Calendar extends Project_Model_Abstract`
in a file called Calendar, placed in Model directory.
Later on I figured out that I dont need this model, so I simply deleted it, along with only reference to it in the controller. (it was used like this
`$this->form = new Project_Model_Calendar();`
)
Apparently there is some memory cache or config file that saved this model, and tries to load it every time.
I get the following error
Zend_Session::start() Error #2 include_once() [function.include]: Failed opening 'Project/Model/Calendar.php' for inclusion
Why do I get this error if I dont use the model anywhere? How can I clear this cache of loaded models?
Could you please help me with it? Please forgive me for asking such unspecific questions, but I need to fix it, and Zend framework is still a mystry for me most of the time.
Including the file will probably still result in an error, even if you're not using it. Make sure it isn't hardcode included in the paths in your php.ini, httpd.conf, or .htaccess files.
When trying to implement this framework I ran into a issue with the directory. When I attemt to use this Zend i end up with
Interface 'Zend\Mail\Storage\Folder\FolderInterface' not found in /home/content/54/9595754/html/zend/library/Zend/Mail/Storage/Imap.php
In the index.php file where I try to display the emails. I use an:
set_include_path
include require_once('Imap.php');
The contents of Imap.php looks like:
namespace Zend\Mail\Storage;
use Zend\Mail;
use Zend\Mail\Protocol;
class Imap extends AbstractStorage implements Folder\FolderInterface, Writable\WritableInterface
So what would i need to add to the Imap.php so that it dosent look inside this directory for the file.
I know understand that I need to try to implement a file in order for the framework to understand the directory they are in however when i try to implement an autoloader I get an error see example below.
require_once '../../../library/Zend/Loader/Autoloader.php';
Yields
require_once(Zend/Loader.php) [function.require-once]: failed to open stream:
No such file or directory in /home/content/54/9595754/html/zend/library/Zend/
Loader/Autoloader.php
Zend framework 2 and most other modern frameworks rely on autoloading for class loading.
You have only required the Imap class but not the dependent interfaces. That's why you get this fatal error.
I'd suggest you setup autoloading in your application. For an example how to set this up you can have a look into init_autoloader.php from the ZendSkeletonApplication.
I need help, cause I am little stuck on this.
I have set up a modular Zend Framework app. Also using -- https://github.com/eddiejaoude/Zend-Framework--Doctrine-ORM--PHPUnit--Ant--Jenkins-CI--TDD- -- i integrated Doctrine 2.
My directory structure is like this:
-aplication/
--default/ --module1
---config
---controllers/
---forms/
---models/
---templates/
---test/
--maintenance --module2
---config
---controllers/
---forms/
---models/
---templates/
---test/
-config
--Bootstrap.php
--aplication.ini
-library/
--Zend/
--Doctrine/
--doctrine.php
--cli-config.php
-sites/
--site1/
---index.php
I have my databse created. I will use some tools to generate YAML files from database.
The next step I want is to generate model classes from these YAML files.
I spend days searching, but I just coudn't find solution to generate classes to models folder of each module. OK, so I would solve the problem by generating these classes in one directory and then move it to their 'original' destination (models folders).
I need help on how to generate these classes. I am developing in Windows, and that is where I want to generate this.
I suppose I have to open cms, point to location of doctrine.php (in library folder) and enter command php doctrine.php + some arguments. But when I do that i have:
[InvalidArgumentException]
There are no commands defined in the "" namespace.
What am I missing? What am I doing wrong?
I will also try to contact author of these files https://github.com/eddiejaoude/Zend-Framework--Doctrine-ORM--PHPUnit--Ant--Jenkins-CI--TDD- to ask for explanation.
Thanks in advance. I would really appreciate your help.
If you need I can write some of my code from Bootstrap and application.ini if you need.
Try to generate the class from YML file .It is possible to use MySQL workbench to sync the database tables and then use the MySQL workbench YML file generator plugin to generate the YML files . Hope it helps.