codeigniter, admin system and auto load - codeigniter

Hello im working on a project and i have a footer and a sidebar that i want to load some information from the database, how can i do so it load the same on all pages.
i want to make a admin system to, how should i do that?, do i need to have a new codeigniter instillation or can i just create a new map in my controller,model and view maps ?.
how you guys doing it?.

The way I would go about it is create a MY_Controller and then put all of your generic logic inside of it and then all of your other controllers extend your MY_Controller. This saves you having to fetch content repeatedly and define and write the same code over and over again inside of your controllers. See Phil Sturgeon's article on base classes and keeping it DRY.
For templating your site including an admin panel, Phil Sturgeon has also created a simple template library that allows you to have themes on your site with different layouts you can switch between, etc.
As for creating an admin panel, Phil has also written a post on the subject as well and he goes into quite a bit of detail about the various ways you can develop an admin panel, which approach is best, etc. Some of the comments on the article are also very helpful too. Read his admin article here.

The templating method I usually use is as such... (it obviously is dependent on whether your sidebar, in your design, comes before/after the "content" in your markup)
<? $this->load->view('path/to/header') ?>
//content of page
<? $this->load->view('path/to/sidebar') ?>
<? $this->load->view('path/to/footer') ?>
Now if you are going to have variables you will need for every view, you can load them globally like so in the constructor of your controller.
$data->some_variable = $some_information;
$this->load->vars($data);
This will make $some_variable available to all views you load from that controller.
An admin system is simply another area of your site/application that is simply protected by an authentication system. You first need a way to verify the user's identity. I generally use Ion_Auth as my preferred auth library, and I have done a fairly extensive write-up on how to set up Ion_auth and your "protected" Controllers in a very clean fashion.

Related

Codeigniter - a dynamic sidebar

I only started with this a couple of days ago, so this may be a silly question...
I have an admin area with its own directory "admin" within the controller folder. So if the user is in the admin area, I want a sidebar to show. But obviously there will be a fair few "pages" (controllers) within the admin area. I have Clients, Services and Dashboard.
In the sidebar (on all pages) I want a list of clients and services so when clicked, it goes to a page and display info for that client/service.
I sort of have it working with add_service(), edit_service(), view_services() etc... but in each of these methods, it seems like I need to load services AND clients models, and pass the data back to each view... in all methods? So if I want to add a service, I click "add service" and it takes me to the add_service(). Do I need the below 4 lines in each method?
$this->load->model('client_model');
$this->load->model('services_model');
$data['clients'] = $this->client_model->get_clients();
$data['services'] = $this->services_model->get_services();
I have read about widgets, but not sure if that's what I need exactly.
Thanks
As you read, all you need is HMVC. This will create a "widget" with your controller, model and views, and you'll be able of calling "a whole": A part of the website wich manage its own part.
One solution is implement https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc into your code, you create a module called "client", and in your "admin" controller you call it. You'll get your client table there, and in your controller "client" you'll be able of call it too, and you'll have exactly the same behaviour. I've implemented wiredesignz HMVC quite times and I think is the solution for your trouble. Anyway, you could also check https://github.com/Bigwebmaster/codeigniter-modular-extensions-hmvc, which is a fork with improvements into the code.
About your sidebar, you'll have to call the widget you'll create with your clients, and you'll have it quickly with only one call, because the module will manage all the behaviour

Ruby Controller Views Actions and Model setup

I have been coding in php for a year now and i have recently decided to start learning Ruby because i heard its a better web language. I'm trying to convert what i have on the website so far into Ruby code, but I'm having trouble understanding the structure for controllers views and models. Heres what i have for php pages.
Homepage(controller)
- index page
- about page
- etc.
Signup(controller)
- index page for signup
Signin(controller)
index page for signin
Admin Page(controller)
Business Page(controller)
Do i make all these controllers and what do the actions and models represent? Is the action the form to signup.
Thanks in advance
I'll try my best to give a condensed answer. RoR follows the MVC pattern (Model, View, Controller) typically controllers handle url requests, models store data and views are used to display the data to the end user. To answer your question, you would not need to create seperate controllers for each individual action. Controllers contain methods for creating, reading, updating, deleting (CRUD) and much more. For example: You might have a UsersController, within this controller are four methods; create, new, update, and delete. This would give you a URL something like /users/new /users/1/edit /users/1/delete
An application like the one you give as an example is quite simple. to seperate an "admin" page is simple and would be something like
<%= if current_user.admin? %>
content only the admin can see
<% end %>
Creating users would involve storing their details in the database, creating a session and allowing users to create and destroy sessions when they login and logout.
The major difference between RoR and PHP (to me, anyway) is PHP makes the views messy by embedding logic code directly into the .html page. Ruby on Rails provides a clean way of seperating logic from html content making it easier to manage or develop between a group.
Pages such as the root page, and about page or contact page might all be methods in the HomeController and would be accesible via /home/index /home/about /home/contact
http://guides.rubyonrails.org/getting_started.html
The above link would be the best place to start learning about the fundamentals.

Using the ion_auth login process and using a templated process to render the login process

I'm a new kid with CI and ion_auth and have both running correctly. I have also created a view/template of a view/template/header and view/template/footer on another page ('welcome') that is a part of a fairly complex html5 responsive template with all my assets in a directory called assets/html5templateV1/css etc.
The question is what is the best approach of using the views/auth/login.php file with the template so I have
A nice looking login page /failed login / request pwd page etc.
The login page uses a templated HTML layout approach (mine is probably incorrect)
Updates to ion_auth can be fairly easily installed
The next person along doesn't say "WT?" and start pulling hair out.
Thanks
There is no need to use ion_auth views or controllers. they are just for reference. we have to use their function as they have define in model for login/logout/register etc... just simply put his model,library and config file to the respective folder of codeigniter in your project and just use their function as they have shown in demo

CodeIgniter - where to put CMS

I come from a background of coding my client website projects from scratch with MySQL and PHP. They are typically public facing sites with a mixture of static content, dynamic content plus a little functionality here and there (i.e. account, searching etc). Nothing too heavy.
So I generally code up a little CMS site to let them update what they need to, put it in a protected folder and that's that.
Now I'd like to use CodeIgniter and more of a MVC approach for my next site. Should I be doing anything to separate the CMS out from the rest of the site or is it simply another area (with its own controllers/models etc) and extra authentication?
There are several good methods to create an admin interface in CodeIgniter described at:
http://philsturgeon.co.uk/news/2009/07/Create-an-Admin-panel-with-CodeIgniter
You probably will want to look mostly at "#2" on his list; it's lightweight and not much additional work.
The CMS is part of the site, if by CMS you mean administration panel / backend of your application, you can use the above link provided by coreylink as it details different ways to create an admin panel.
My personal preference is to create a folder called 'admin' in my controllers directory and create semantically meaningful names so my urls are webapp.com/admin/users and so on.

How to create my own form in joomla

I want to create my own form that are submitted and values of that form will be stored in joomla database. How can i used the Joomla connection code to interacte with the joomla database.
If you just want to get your work done, there are some components already avaiable in Joomla Extension's website to your form's needs. CkForms is a good one, you can create simple forms with it that are automatically saved in the database (supports upload of files too).
If you want to learn how to write extensions in Joomla, you should read Joomla Official Documentation website.
Extensions in Joomla are divided in "Components", "Modules" and "Plugins". More informations about these differences can be found here and here.
What you're trying to achieve sounds a "component" to me. Downloading the CkForms and reading it's source code should get you started to Joomla's way of writing components.
EDIT: Joomla has a huge API with a lot of features. It has a database module of it's own, with insert methods and such. Reading Joomla's API website before implementing your component it's a good idea to avoid "reinventing the wheel" and it's a good practice since those methods are extensively tested by all Joomla users.
The JForm class helps you build forms.
Documentation can be found here:
joomla CMS: http://docs.joomla.org/API16:JForm
joomla API: http://api.joomla.org/11.4/Joomla-Platform/Form/JForm.html
This class provides you with ready to use form elements and form loading and/or processing methods
This class includes validation methods, date picker control, color picker, etc.
Of course, as another mentioned above, if you are building a module, component, or application, you will need to learn how to to develop a module, component or application. Of these three, the module is the easiest to implement.
The application gives you much freedom b/c you are not constrained to the CMS paradigm, front and back end complexities. However, there is little documentation about how to develop applications with Joomla framework b/c joomla as a framework is relatively new
This tutorial gets you started understanding how to use JForm to create a form in Joomla: http://www.ostraining.com/blog/how-tos/development/getting-started-with-jform/
Or you could just create add a html module to any position and then write the form in html i.e.
<form method="post" action="mycreatedpage.php"> <input type="text"/> <input type="submit">
Now just create a page that handles the code by emailing or inserting into db. I havent tried it but i think it should work.
Looks like everyone already told you almost everything I know except for the component creator. Very easy to use, and it follows Joomla standards. Will get you up and running within minutes.
I have got good working experience with Joomla RSForm Pro. It has got options for
validation
user email/admin emails on submit
file uploads
and many more
Good tutorials too. Get started with http://www.rsjoomla.com/support/documentation/view-knowledgebase/21-rsform-pro.html
Good luck!
Create View.
Create Model.
Create Table.
Create Controller ( if Needed ).
Create Form xml file.
Go here for more information:
http://docs.joomla.org/Standard_form_field_types
Take a look at the Chronoforms extension - does more than you want.
You have two options:
Use an already built custom form extension
Create your own custom form extension (or outsource it)
Now if you only want to modify the user registration form, then you can do some PHP customization to accomplish your goal.
Making forms in Joomla can be done in a couple of ways.
If you just wanted a contact us, you can just create a page with a menu item for the User contact form. This gives you a page with a Members address and contact form. So all you would need to do was add the user as the company of the websites home address and email. But the form is very basic, name, title, textarea for message.
Next up from that you could just make a Custom HTML module add add a form to it in plain HTML like +Sean said above this, you would need to code in PHP your own form process script. You would not get error in form data checking unless you also wrote it.
Next you might rather look on the Joomla Extension Directory JED for one of the good extensions for 3 and 2.5 Joomla RSForms!Pro is good, and can do all we have needed. This lets you add fields one by one and move your form around. Then can auto generate or custom the html of the form.
You can easily create your own forms with Fabrik
Chronoforms are now a days a very popular solution for custom forms in joomla. Chornoforms support twitter bootstrap also. In simple 5 steps you can create a contact form with unlimited fields and also embed various function like DB save, Email, Thanks Message, Redirection on any page. There is events and events will have particular events.
Also possibility of extension of Normal joomla registeration. It will not extend the core registration but at the time of registration you can take various information from users.
I would use Chrono Forms, they work really well and are easy to use.
Download here
Here is a full tutorial on the new Chronoforms 5 to help you get started quickly and understand most of the features available.
CLICK HERE
You can use plugin to insert external php form in content. It is easy and you don't need to make plugin etc. Please use this.
I suggest you to use breezingforms: http://crosstec.de/en/extensions/joomla-forms-download.html
It's one of the best solutions for custom form creation in joomla.

Resources