Skip to content

Getting Started

Bill Lee edited this page Nov 11, 2017 · 4 revisions

Getting Started

The following uses the sample_simple, provided, in the repository. (We'll cover the more realistic sample_project example, later).

If you haven't already, make sure you understand the simple concepts in ccPhp Overview, first.

Simple Template

sample_simple demonstrates the bare essentials of a ccPhp-based application.

  1. Copy/clone ccPhp to your web server.
  2. Create an app directory to hold application-specific source files.
    1. Move or copy the sample_simple files to that location.
    2. In app.php, adjust the reference to the ccPhp's ccApp.php to the location where you put ccPhp.
  3. Determine the web-accessible directory that corresponds to the URL you want your application to be accessible through.
    1. Move/copy the sample_simple's public files to the pubic location. Be sure to include the .htaccess file.
    2. Adjust the index.php's reference to app.php to find it in the location on your server.

Alternatively, in step 3., you can create a symbolic-link to the public directory and leave it in place—you might be able to avoid changing index.php's reference to app.php (depending on your operating system and web-server).

Note that app.php, in this example, defines MyPage in its source, for use as the page for the application. Normally, such classes would be defined in their own files. You can change the implementation of MyPage::render() to generate whatever content you'd like.

Run it!

  1. Make sure the web-server is running and that you know the URL to access your application (the directory where the index.php is located).
  2. Use a browser to access the URL
  3. See your render() results.

What Does app.php Do?

  1. Get a reference to the app instance of ccApp via createApp().
  2. Register an instance of your rendering class with ccApp via setPage().
  3. Tell the app to do it's thing via ccApp::dispatch().
  4. dispatch() invokes the page's render() method, MyPage::render() and the page code does its thing.
  5. MyPage::render() returns true or false, true if it handled the request, false if it did not. ccPhp does not check whether render() did anything, only the result. If it returns false, then a "Page not found" (result code, 404) is returned.

How is the Web-server Involved?

  1. A user accesses your application via a URL.
  2. The web-server loads index.php and PHP runs and loads app.php, which kicks off the rest of the processing.
  3. ccApp invokes MyPage::render() which generates output that is sent to the browser and displayed to the user.
  4. render() returns true and processing is essentially over.

Next…

You can try having render() return false, instead, to see what happens.

Still, this example is overly simplistic and doesn't do anything more than what you could have achieved with a single .php file without knowing anything about ccPhp.

Next, we'll cover a more robust example, in sample_project.

Clone this wiki locally