Download the PHP package slaxweb/ci-basecontroller without Composer

On this page you can find all versions of the php package slaxweb/ci-basecontroller. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package ci-basecontroller

BaseController

Base controller for CodeIgniter, helps you with loading views, subviews, and populating them with data and loading of language as well as injecting said languages into the view data.

The idea for the BaseController came from Jamie Rumbelows base controller, with some additions and changes. At this point I would also like to thank Marco Monteiro and Sami Keinänen for their help.

If you run into issues or have questions/ideas, please submit a ticket here on GitHub.

This is still in development phase, but is production ready. All existing stuff will be there and if changes do occur, old ways will be kept around in deprecated state.

Table of contents

Install

The easiest way to install at the moment is to use composer. Simply create composer.json file in your project root:

Then run composer.phar install. When finished, enable composer autoload in application/config/config.php.

Next create the directory in application/config/ called slaxweb, and copy the configuration file found in install/slaxweb/basecontroller.php to the newly created directory. Or use the installation script found in install directory.

Congratulations, BaseController is installed.

View loading and data

Example

Basic usage

To start using, all your controllers must extend \SlaxWeb\BaseController\BaseController instead of CI_Controller. If you are already extending MY_Controller, then extend \SlaxWeb\BaseController\BaseController in MY_Controller.

And this is it, after a controller method is done executing, BaseController will automatically load the view file associated with this controller method. The default view being loaded is: application/views/(controllerdir)/controllername/controllermethod/main.

Disable view loading

Some controller methods do not load views. In this case set BaseController property view to false:

Change view file

Want to load a different view file and not the default one? No problem, just set the desired view file to view property.

Load sub-views

WARNING! Loading of subview has been changed in version 0.4.0. Please see UPDATE0.4.0.md for more information.

If you need to load subviews into your main view, you can do so, by assigning a nested array to the BaseController subViews property. First level array holds the name of the sub-view parameter injected into view data, as the key. The value is an array of arrays. The bottom most array holds the view path and name, and any subview specific data with the key names, "view" and "data" respectively.

Data is not a required paraeter and can be ommited.

Display the subview in the main view:

View data

To load data into view, simply assign it to the viewData property array.

Controller 404 page

If a controller method is not found, the Basecontroller will search in the routed-to controller a _404 method and call it, so you can have custom 404 pages per controller. If it is not found, it will call the CodeIgniters show_404 method, and the CodeIgniter 404 page will be displayed as per normal operation.

Languages

BaseController also autoloads language files and loads properly prefixed language strings into the view data before loading the view. Language filename must have the same name as the controller, and all language strings that will be injected into the view data, need to have methodname_ prefix in the language string key.

Example

Basic usage

By default, base controller will auto-load the language file that has the same name as the controller name, from the default language directory. By default that is english, changeable in CodeIgniter config. By default it will load all language strings which have the methodname_ as the prefix in the language string key name.

Above will try to autoload application/language/english/Contrlr_lang.php and inject translated strings.

In the view, vars $var1, $var2, and $var3, will be available.

No languages

To disable loading of languages, simply disable it by setting property langFile to false. WARNING! Property used for disabling the language file loading in 0.1.* versions is includeLang!

Language file

In order to load a different language file, set the langFile property.

If you wish to load multiple language files, set an array with those language file names to the langFile property.

Language prefix

To change the prefix from the default method name, set the langPrefix property.

Non-Default language

If you want to load a non-default language, you have to set it with the language property.

Templates

Base controller also supports basic templating. At the moment only by setting a header and footer view.

Example

DEPRECATED - Setting template files

In order to set the header and/or footer files, properties head, and foot must be set. Then the header view will be loaded before the controller view(s), and the footer will come after.

DEPRECATED - Disable template

If you have set the template files, but would not like to display the header and footer views, you need to set the include property to false.

Layout

Instead of header/footer files, BaseController now provides layouts. The layout is the whole template and your controller view gets injected into this layout view through the mainView variable. You have four options:

Manual view loading

BasicController also allows you to manually load any view file you want. Because BaseController is using the ViewLoader, you can access it through the protected _viewLoader property. For help with using the ViewLoader, please read the readme here.

Models

BaseController now tries to auto-load the default model for this controller, which needs to have the same name as the controller it self, with the _model suffix. You can also add additional models you may want to load to the models property. Models are then accessible as $this->{Model name}, without the _model suffix.

Example

CRUD

CRUD stands for Create, Retrieve, Update, Delete. BaseController provides basic CRUD methods that retrieve data, inject them into the view data as well as take post data for creation, update and deletion of database data. As long as your models provides the necessary methods for such operations. To be on the safe side, install the BaseModel, and extend your model from it.

There are 4 methods for CRUD:

All but index(Create) are accessed through POST HTTP request method, and also all 3 provide a means to load a specific view after they have completed, and also set an error in view data if the operation was not successful. This is done through 3 different BaseController properties:

Those need to contain the string location of the view to be loaded. If left empty, the respective default view will be loaded as per methods HTTP GET request counterpart (update, create, delete).

Update and Create also provide a means for data validation, all you need to do is set a createRules or updateRules public properties in your controller. Those need to contain the normal CodeIgniter validation rules.

On error, Create, Update and Delete will inject the error strings as createError, updateError or deleteError variables. There are 3 types of errors: validation error, create error and update error, as well as a fourth, generic error for delete method. In order to get the message, your controller language file has to be loaded and it needs to contain following keys:

If those are set, you will get this error message in your view data. On validation errors you can normally use the CodeIgniter validation error printout as well.

ChangeLog

0.4.0

WARNING! This version breaks backward compatibility! See UPDATE0.4.0.md for more information

0.3.1

0.3.0

0.2.3

0.2.2

0.2.1

0.2.0

0.1.2

0.1.1

0.1.1.0

0.1.0.3

0.1.0.2

0.1.0.1

0.1.0.0


All versions of ci-basecontroller with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
slaxweb/ci-viewloader Version 1.0.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package slaxweb/ci-basecontroller contains the following files

Loading the files please wait ....