Skip to content

vishwambhar/fundvis

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fund performance visualisation

for server side code & web page

Framework that we are using

  1. Codeigniter 2.1.4 - PHP Framework
  2. RESTful API for Codeigniter

Files structure

Please refer to the document in Codeigniter to have a detail understanding. Please basically it can be separated into two parts, application and system

Application

It is the place where our main application will be put, all later codes commit should be into this file.

config

All the static fields like database location (in database.php) will be stored in this folder. You will need to modify the error_message.php in that folder later on.

controllers

The main place where all request is first processed, please take a look on user.php for example.

helpers

Our custom helper for doing our routine jobs will be put in here. It exists as a form of function but not class, you can think it is a Utility class that has static methods. Currently I do not see a need for adding any helper file in there, using the one provided by Codeigniter is good enough.

libraries

Our custom library for doing our routine jobs will be put in here. And it always exists as a form of class. Our two main libraries are REST_Controller.php (for handling RESTful request) and CORE_Controller.php (for handling session checking and validation as well as formulate the error and generate error message). Normally, you do not need to change the file in there, it will be covered by me.

models

The main place where all communications to database will happen in here. Please take user_model.php as the example.

views

The main place to return some views to user, since we don't need that (we only return JSON), you can skip this folder.

System

The core part of the framework, normally we will not modify any files in there. And it shares the same structure as the Application folder.

Note on creating new file

Common

Please start with this line

``` // Please ignore the "?>" at the end. ```

And end with this

```PHP /* End of file __filename__.php */ /* Location: ./application/__folder__/__filename__.php */ ```

In controllers

For all RESTful controller,
please incl. this statement before defining the class

```PHP require_once (APPPATH. 'libraries/REST_Controller.php'); ```

And define the class like this
For example, if you have a class called `trip`

```PHP class Trip extends REST_Controller { public function __construct() { parent::__construct(); $this->load->library('CORE_Controller'); $this->core_controller->set_response_helper($this); }
// other functions go below...

}

<p>
And name the file as trip.php
<br>
Example can be found in user.php
</p>

<h4>In models</h4>
<p>
Define your class like this
</p>
```PHP
class Trip_model extends CI_Model {
	// define the KEY and table name in here

	// methods go below...
}

And name the file as trip_model.php

That's all you need to know when creating a new class.

Special note on classes in controllers folder

Currently I have not yet finished writing all checking strategy on the CORE_Controller.php, but you still need to use that class, just initialize the class like the example above will be good enough.

- Please use core_controller as your responsing method
e.g. If you need to response failure message back to the app, please do this

```PHP /** * @param $error_code INT This will be referenced back to the error_message.php in the config folder using the error code * @param $override_custom_message STRING Once it is not null, it will replace the default message referenced in the error_message.php, case like validation error would be a good place to use $override_custom_message */ $this->core_controller->fail_response($error_code, $override_custom_message); ```

Example: controllers/user.php -> register_post() method
If you need to response success message back to the app, please do this

```PHP $this->core_controller->successfully_processed(); ```

After calling the above two methods, the server will STOP processing remaining codes.
More often enough, you need to send data back to client not only success message, you can do this

```PHP /** * @param $key STRING The key used in the return JSON data pack, `Exception` will be thrown if the key is already used before, reserved keys are `session_token` and `expire_time` * @param $value ANY The value that will matched with the KEY, $value should not be null */ $this->core_controller->add_return_data($key, $value);

// Note that this method can be chained, i.e. $this->core_controller->add_return_data($key1, $value1)->add_return_data($key2, $value2)->add_return_data($key3, $value3);

// Please remember to call successfully_processed() in the end of the chain if no more processing is needed.

<p>
On the call of fail_response(), all added return data <b>will be dropped and will not be included</b> in the return message.
</p>

About

Visualisation of fund performance

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published