-
Notifications
You must be signed in to change notification settings - Fork 0
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.
sample_simple
demonstrates the bare essentials of a ccPhp-based application.
- Copy/clone ccPhp to your web server.
- Create an app directory to hold application-specific source files.
- Move or copy the sample_simple files to that location.
- In app.php, adjust the reference to the ccPhp's ccApp.php to the location where you put ccPhp.
- Determine the web-accessible directory that corresponds to the URL you want your application to be accessible through.
- Move/copy the sample_simple's
public
files to the pubic location. Be sure to include the.htaccess
file. - Adjust the index.php's reference to
app.php
to find it in the location on your server.
- Move/copy the sample_simple's
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.
- 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). - Use a browser to access the URL
- See your
render()
results.
- Get a reference to the app instance of
ccApp
viacreateApp()
. - Register an instance of your rendering class with
ccApp
viasetPage()
. - Tell the app to do it's thing via
ccApp::dispatch()
. -
dispatch()
invokes the page'srender()
method,MyPage::render()
and the page code does its thing. -
MyPage::render()
returnstrue
orfalse
, 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.
- A user accesses your application via a URL.
- The web-server loads
index.php
and PHP runs and loadsapp.php
, which kicks off the rest of the processing. -
ccApp
invokesMyPage::render()
which generates output that is sent to the browser and displayed to the user. -
render()
returns true and processing is essentially over.
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
.