How to layout base class and 3 extended classes in CodeIgniter? - codeigniter

This is the layout I'd like to use for controllers in CodeIgniter:
(base) editor
(extend) design
(extend) content
(extend) ...php
...where editor is a base class and design, content, etc. controllers extend editor. The editor class will have methods that are publicly accessible from the extended classes URL segments.
I've read some topics on here, and they recommended:
Library - this won't work as methods won't be publicly accessible (am I correct?)
Put base class in the same file as extended class and name the controller that - this won't work since I need to extend from multiple places.
Put all the files in the controllers folder, add require statements to each extended class - is this bad form?
I'm new to CI. What's the proper/correct way to handle this?
Thanks!

http://www.ellislab.com/codeigniter/user-guide/general/core_classes.html
extend the core CI controller with MY_Controller, then extend MY_Controller with your other controllers. all the other retain the functionality in MY and MY retains the functionality of the base controller
There is also this article which allows more controllers that don't have the MY_ prefix, which I use and find VERY useful!
http://philsturgeon.co.uk/blog/2010/02/CodeIgniter-base-Classes-Keeping-it-DRY

Related

How Laravel requests behave about controller files compilation

In Laravel, when a request mapped to a specific controller method is made, does Laravel access/compiles all other controller files or just the file from involved controller?
Most of the classes you create in a Laravel application are loaded as needed. This includes Models, Controllers, Repositories... pretty much everything.
Autoloading is achieved using the PSR-4 spec. If you have a namespaced class like...
<?php namespace \Foo\Bar;
class Baz {}
Then it should live in...
app/Foo/Bar/Baz.php
When this class is used for the first time, the framework will attempt to load the class from that location.

ASP.NET Web API Help Pages Omit Controllers That Inherit From A Base Controller

I have a controller that I want to generate documentation for using ASP.NET Web API Help Pages.
When I directly inherit from ApiController the documentation appears:
public class ExampleController : ApiController
But when I inherit from a base controller, it is omitted:
public class ExampleController : ApiBaseController
...
public class ApiBaseController: ApiController
I have switched to delegation rather than inheritance, but I wanted to know how to make it work with inheritance.
Here is a tip I picked up in my experimentation.
The documentation leans heavily on the routes in your API config. If your controller isn't covered by a route, it won't show up. Additionally, the order of the routes in your API config is the order of the operations in your documentation.
To cover both of these points I have created named routes for each controller. This has the added benefit of making each route specific, rather than a single route with lots of optional bits. This ensures all my operations appear in the documentation, in a good order.
I have also added the API tester so the API can be called directly from the documentation.
Check the permissions in your base class. I had the same issue and is was a result of methods that should have been set as internal being protected.
Make sure that all your methods that need to be accessed by the parent item are set to internal and any methods that override the ApiController are set to protected.
Post your code if it still doesn't work.
Works like Gravy :)

Regarding Symfony2 Session

In symfony2 every user created controller extends Controller Class as shown below,
class MyController extends Controller {
thus functions related to session handling are available with $this object, But controllers in Vendor and Core don't extend Controller class thus don't provide access to session related functions. So is there any way to use these functions without extending Controller class.
Presently I am using $_SESSION[], for setting and getting session variables.
Is there any way other than above.
Symfony2 provides a service for sessions, this is what you're trying to retrieve. All services in symfony2 are retrieved using the service container, which is what you're referring to with
$this->get('session');
To properly make use of the service container in your own controllers you can either...
Configure your controllers as services (see: here)
Extend the base Controller class provided by the Symfony2 stack (making the get() method available to your child Controller)
The first option is the correct way to go, you have full control over what services are then injected into your respective controllers (see service container documentation)

using App.xaml.cs Reference in another project present in same solution?

hi i am having a different projects in my solution in the initial project (default project) i am accessing the global reference to App.xaml.cs in this way :-
App objref = (App)Application.Current;
But now i have added new project to my solution and trying to access the app.xaml.cs in the same way as defined earlier but i am not able to access app.xaml.cs ?
1)can i know the reason
2)What should i do if i want to use it in both the projects ?
Please let me know
Thanks in advance.
You can access it, but the new project will not be familiar with the derived App class that is in your project. To explain further we need to take inheritance into consideration.
There's a generic definition for the Application class that exposes a number of predefined methods. Your App.xaml.cs is a new class definition that is derived from the Application class. It has the methods it inherited plus what ever methods and properties that you've added. To make use of these any code that is seeking to use your extra properties or methods must have access to the class definition. Your classes in the other projects that you've added do not have access to this definition.
You'll need to make a class or interface definition that both projects have access to. There are several ways of organizing this. I'll present one.
Create your main project in the solution. This contains your
App.xaml.cs.
Create your class library project that contains the
other code.
Create a third project called Common that only contains
an Interface definition.
On the Interface definition define all of the methods/properties
that you want both your class library and main project to have
access too.
Have App.Xaml.cs implement this interface.
In the Class Library access var appReference =
(IMyInterfaceName)Applcation.Current. You'll have access to the
methods that were defined in the interface

Overload Library Class Methods with Magento 1.6v or higher

I have Magento version 1.6 and I want to like overload a method in a class which is located in {root}/lib folder. I have seen that there are no problems If I want to overload magento methods in the {root}/app/code/mage folder.
But my problem is, how can I overload specific methods in a class from magento library lib folder?
AFAIK, the only way to override the lib class file is to use the same folder structure as that of lib in app/code/local pool.
For example if you want to override
lib/Varien/Image.php
then you should copy the file to:
app/code/local/Varien/Image.php
But in case of lib class's method overriding. i don't think if that's possible unless you modify the autoload classes.
Thanks

Resources