extending native session class codeigniter 1.7.2 - class

I'm using native session library to replace the built in session library in CI. I need to extend the class but when I drop in MY_Session.php, CI reverts back to the old /system/libraries/Session.php.
How to I extend a class that's replaced a core CI class like Session.php?

Simply by naming your class files identically to a native library will
cause CodeIgniter to use it instead of the native one. To use this
feature you must name the file and the class declaration exactly the
same as the native library. For example, to replace the native Email
library you'll create a file named application/libraries/Email.php
-user guide
then call it
class MY_Email extends CI_Email {
public function __construct()
{
parent::__construct();
}
}
Loading Your Sub-class:
$this->load->library('email');
EDIT
Try this:
Just load your new library (the one doing the extending):
Then, let's say we have Session.php and Mysession.php
<?php
load_class('session', false);
class Mysession extends Session {
//your code
}
You don't need the MY_ name tag still, I think you want to reserve that for it's original intended purpose to avoid confusion.
.. else just use an include() or require() :P

Related

Use existing classes in prestashop module

I am preparing a custom module for prestashop. I want to use in it some classes that exist in prestashop already (Orderdetail.php).
How can I do this? Is the code below sufficient or do I need to include something else in addition?
$order = new OrderDetail;
Yes, the native classes can be called like that.
$order_detail = new OrderDetail();
However to use custom classes you need to include their files in the script you want to use them.
include_once 'path_to_custom_class_file';
class MyModule extends Module {
public function aMethod() {
$myClass = new MyClass();
}
}
To make an instance of your module you have to use this code:
$mymodule = Module::getInstanceByName('mycustommodule');
Than you can use method of your module core.
E.g.
$mymodule->myCustomMethod('x', 'y');

custom code generation in xtext

I am using Xtext do define a new language. I wish to generate code from this language, however I do not want to use the automatically suggested doGenerate function. Instead, I need to use a java code (not Xtend), that I can call from the build process.
Of course in that java code I want to be able to use the 'resource' that is passed to the original suggested function, so I can access all the information from the DSL's code.
I Believe by default the generator is implementation is an xtend file but there is nothing stopping you from changing this to a java file, you just need to override the binding in your [LanguageName]RuntimeModule class as follows:-
public class ExampleRuntimeModule extends com.example.AbstractExampleRuntimeModule {
#Override
public Class<? extends IGenerator> bindIGenerator() {
return YourOwnGenerator.class;
}
}
Where YourOwnGenerator should implement IGenerator.

How to add new class and autoload in zend framework

I am new on Zend framework and using first time it. I am looking for simple basic tutorials which I can read in very short time. I also stuck on if I want to add new class in Zend library. And it should also auto load when I make any new controller.
Please give your opinions if you have.
Regards,
This helped me At the beginning:
http://www.zendcasts.com/
http://devzone.zend.com/search/results?q=autoload (just search)
As autoload your class, This is the my way:
Create folder 'My' into library/
in it create folder 'Utils' and in Utils file 'Utils.php' so the path is library/My/Utils/Utils.php
For this path You must call class: class My_Utils_Utils{ ... }
and in configs/application.ini Put
appnamespace = "Application"
autoloaderNamespaces.my = "My_"
Then you can use namespace My_ and class My_Utils_Utils
In controller: $test = new My_Utils_Utils();
I am looking for simple basic tutorials
Here are a few tutorials I found while googling:
Official quickstart tutorial
A great book by frequent ZF-contributer PadrĂ¡ic Brady: Survive the deep end!
http://akrabat.com/zend-framework-tutorial/
Page with different tutorials: ZFTutorials.com
I also stuck on if I want to add new class in Zend library
You should not add new classes to the library per se, but instead create your own library or add classes in the "models"-folder/folders (if you use the modular project layout). Autoloading is achieved by utilizing Zend_Loader_Autoloader and its subclasses. As long as you follow the PEAR convention, i.e. if you have a class MyLib_Database_Table, then it should be inside the folder MyLib/Database, and the filename should be Table.php. (also make sure that the parent folder of MyLib is on the project include path.
To autoload simply use new MyLib_Database_Table, and the autoloader will load the class behind the scenes if necessary. Since 1.10 (I think), the autoloader also fully support PHP 5.3 namespaces. I.e:
// Filepath: lib\MyLib\Database\Table.php
namespace MyLib\Database;
class Table {
}
will work with the same folder structure. Code example:
use MyLib\Database\Table;
class IndexController extends Zend_Controller_Action
{
public function indexAction ()
{
$myTable = new Table();
}
}
auto load when I make any new controller
I'm not quite sure what you mean here. ZF does not have any dependency injection setup per default. But you can instantiate your classes without requiring them first if that's what you mean.

Where do I place base action class in Symfony plugin?

I'm creating a plugin for my symfony project, which includes a base action class, i.e.:
<?php
// myActions.class.php
class myActions extends sfActions {
/* ... */
}
Where in my plugin folder (e.g.: plugins/sfMyPlugin/???) should I place this file?
The goal is to have actions that are NOT a part of this plugin extend this class, hopefully having the class be autoloaded (similar to if it were placed under apps/my_app/lib). If it can't be autoloaded, how do I get symfony to include my php file?
You typically put it in your plugin's lib directory. The general conventions is also to to name with Base in the name so given your example that would be BasemyActions. Then you would also make an empty concrete class called myActions and you would extend that within your plugin thus allowing other user to complety replace myActions with their own implementation (so long as it extends the base class) or to simply extend myActions.
you can place it in the lib directory of your plugin. This is what the generate:plugin-module task of the sfTaskExtraPlugin does.

Model Helper Zend

from what i know there is only action helper & view helper available at zend framework.
is there any model helper?
or how we can implement the model helper?
There's nothing in ZF actually called a Model helper - but if your model is accessing a database table you might want to create it as a class which extends Zend_Db_Table_Abstract. See examples in the ZF manual: http://framework.zend.com/manual/en/zend.db.table.html
In Zend Framework there is nothing defined for the models helpers like there is for the views helpers, however you can work around it and still preserve the application design (avoid using the library folder).
The way I do it is by adding a Helper folder inside the models one. Then you have to name your class like this:
class Application_Model_Helper_DateHelper
{
...
}
Then the autoloader will take care of finding it and loading it.
Unfortunately this naming is a little different from how you do it in the views folder. In the views folder you can create a folder named helpers and use a naming convention like:
class Zend_View_Helper_DarkBlueMenu extends Zend_View_Helper_Abstract
{
...
}
However, if you name the folder inside models as helpers then the classes inside it have to be named like this:
class Application_Model_helpers_DateHelper
{
...
}
First I add this line in my configuration file ie. application.ini:
includePaths.library = APPLICATION_PATH "/../library"
Then I add a class
class App_Model_Helper {
public static function resultAggregation($results) {}
//.... all the helper you need
}
in a file placed in ..library\App\Model\Helper.php
This is the only way I found to factor the code I use in the model.
The helper method can then be called from the model:
App_Model_Helper::resultAggregation($results);
I am aware this breaks the OOD, so if any one has a better and cleaner solution I would greatly appreciate.