Ask about library |
Hello from indonesia. I try to make my own library (Haha i don't if it is right or not). Okey first, i'll put the code's
PHP Code: class Donaturlib { The code is working fine, but my real problems are : 1. What is the function of library ? 2. Is my library right ? 3. If right, what the different with models ? Sory, for my bad english.
0. Use English identifiers, otherwise it is it is very hard reading code. "Donaturlib" name does not tell me anything about he purpose of this library.
1. See http://www.codeigniter.com/userguide3/ge...aries.html This is the formal, technical explanation about libraries. From your perspective there are two main reasons for making libraries: just to collect code within relatively independent methods; or to use OOP - then you have classes that are aspect focused, the methods serve a concrete functionality. CodeIgniter libraries at the moment follow the singleton pattern (other instances may be created under different property names), they also have a conventional way to access in initialization specific to them configuration options. 2. There is room for criticism about your library. At the moment it is small, but it tends to do many things alone. Try to split the concerns, let this library have a singlepurpose. For example, the getPeople($username) method IMO should be in a separate model that deals with the users. You have HTML code inside the method is_admin(), the place is not right, HTML usually is within views. The method security() seems pretty exotic. It is not clear why do you use cookies directly, also, I don't see encryption/decryption of these cookies. 3. The difference between models and libraries is technical. Models don't have the same access on initialization to the configuration options as libraries have, but models have a property for accessing the database. Semantically there may be no difference, you may implement business logic as a model (usually) or as a library. A shopping cart could be a library or it could be a model. Here I share my subjective perception, of course.
Thank for replying. I use bahasa indonesia .
1. Okey, because in 'old place' i have troubled to find the definition 2. What is the IMO things?. The method security is using some randstring. 3. Oh oke i get it. Do you mind if i ask your email ? so i can send you my script. But, i'll fix my script first.
another question from me.
If i want to give 'flashdata' but the flashdata is html like above , where should i put it ? sorry if i to much asking, i really want to understand it
This is a good question. I have a little bit dirty approach, but it is practical and saves time.
Within your "views/" folder make a file "feedback_messages.php" with the following sample content: PHP Code: <?php defined('BASEPATH') OR exit('No direct script access allowed'); Then include directly this file within your view file that makes the final html layout (the html template of the pages), i.e. Include this file at the desired place within your html template. This is a widget that shows feedback messages to the user. The messages may come from 3 different sources: - directly passed into the view variables; - flash data items - activation by JavaScript - if your AJAX calls return feedback messages you can show them with this widget too. You may pass text messages, of course you may pass simple HTML too, but you don't need to pass the design of the text messages again and again many times. |
Welcome Guest, Not a member yet? Register Sign In |