100% found this document useful (1 vote)
20 views

CodeIgniter for Rapid PHP Application Development Improve your PHP coding productivity with the free compact open source MVC CodeIgniter framework 1st Edition David Upton instant download

The document is a promotional overview of the book 'CodeIgniter for Rapid PHP Application Development' by David Upton, which focuses on improving PHP coding productivity using the CodeIgniter framework. It includes links to various other related eBooks and provides a detailed table of contents outlining the chapters and topics covered in the book. The author, David Upton, shares his background and expresses gratitude to contributors and reviewers involved in the book's creation.

Uploaded by

virtsalfre
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
20 views

CodeIgniter for Rapid PHP Application Development Improve your PHP coding productivity with the free compact open source MVC CodeIgniter framework 1st Edition David Upton instant download

The document is a promotional overview of the book 'CodeIgniter for Rapid PHP Application Development' by David Upton, which focuses on improving PHP coding productivity using the CodeIgniter framework. It includes links to various other related eBooks and provides a detailed table of contents outlining the chapters and topics covered in the book. The author, David Upton, shares his background and expresses gratitude to contributors and reviewers involved in the book's creation.

Uploaded by

virtsalfre
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

CodeIgniter for Rapid PHP Application

Development Improve your PHP coding productivity


with the free compact open source MVC
CodeIgniter framework 1st Edition David Upton
pdf download
https://ebookname.com/product/codeigniter-for-rapid-php-
application-development-improve-your-php-coding-productivity-
with-the-free-compact-open-source-mvc-codeigniter-framework-1st-
edition-david-upton/

Get Instant Ebook Downloads – Browse at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Multi Tier Application Programming with PHP 1st Edition


David Wall

https://ebookname.com/product/multi-tier-application-programming-
with-php-1st-edition-david-wall/

SOA and WS BPEL Composing Service Oriented Architecture


Solutions with PHP and Open Source ActiveBPEL 1st Ed.
Edition Yuli Vasiliev

https://ebookname.com/product/soa-and-ws-bpel-composing-service-
oriented-architecture-solutions-with-php-and-open-source-
activebpel-1st-ed-edition-yuli-vasiliev/

Building PHP Applications with Symfony CakePHP and Zend


Framework 1st Edition Bartosz Porebski

https://ebookname.com/product/building-php-applications-with-
symfony-cakephp-and-zend-framework-1st-edition-bartosz-porebski/

Dipole Quadrupole Theory of Surface Enhanced Raman


Scattering 1st Edition A.M. Polubotko

https://ebookname.com/product/dipole-quadrupole-theory-of-
surface-enhanced-raman-scattering-1st-edition-a-m-polubotko/
The Healing Echo Discovering Homeopathic Cell Salt
Remedies Schuessler Tissue Salts 1st Edition Vinton
Mccabe

https://ebookname.com/product/the-healing-echo-discovering-
homeopathic-cell-salt-remedies-schuessler-tissue-salts-1st-
edition-vinton-mccabe/

An Introduction to English Phonetics 3rd Edition


Richard Ogden

https://ebookname.com/product/an-introduction-to-english-
phonetics-3rd-edition-richard-ogden/

The Dragon Has Two Tongues Essays on Anglo Welsh


Writers and Writing Glyn Jones

https://ebookname.com/product/the-dragon-has-two-tongues-essays-
on-anglo-welsh-writers-and-writing-glyn-jones/

Taste of Modernity Sufism Salafiyya and Arabism in Late


Ottoman Damascus Itzchak Weismann

https://ebookname.com/product/taste-of-modernity-sufism-
salafiyya-and-arabism-in-late-ottoman-damascus-itzchak-weismann/

Essential App Engine Building High Performance Java


Apps with Google App Engine 1st Edition Adriaan De
Jonge

https://ebookname.com/product/essential-app-engine-building-high-
performance-java-apps-with-google-app-engine-1st-edition-adriaan-
de-jonge/
Ireland For Dummies 4th edition Dummies Travel
Elizabeth Albertson

https://ebookname.com/product/ireland-for-dummies-4th-edition-
dummies-travel-elizabeth-albertson/
CodeIgniter for Rapid PHP
Application Development

Improve your PHP coding productivity with the


free compact open-source MVC CodeIgniter
framework!

David Upton

BIRMINGHAM - MUMBAI
CodeIgniter for Rapid PHP Application Development
Improve your PHP coding productivity with the free compact
open-source MVC CodeIgniter framework!

Copyright © 2007 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of
the information presented. However, the information contained in this book is sold
without warranty, either express or implied. Neither the author, Packt Publishing,
nor its dealers or distributors will be held liable for any damages caused or alleged to
be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.

First published: July 2007

Production Reference: 1160707

Published by Packt Publishing Ltd.


32 Lincoln Road
Olton
Birmingham, B27 6PA, UK.

ISBN 978-1-847191-74-8

www.packtpub.com

Cover Image by Vinayak Chittar ([email protected])


Credits

Author Project Manager


David Upton Abhijeet Deobhakta

Reviewers Indexer
Rick Ellis Bhushan Pangoankar
Derek Allard
Proofreader
Development Editor Chris Smith
Douglas Peterson
Production Coordinator
Assistant Development Editor Shantanu Zagade
Nikhil Bangera
Cover Designer
Technical Editor Shantanu Zagade
Ajay S

Editorial Manager
Dipali Chittar
About the Author

David Upton is a director of a specialized management consultancy company,


based in London but working around the world. His clients include some of the
world's largest companies. He is increasingly interested in web-enabling his work,
and seeking to turn ideas into robust professional applications by the simplest and
easiest route. He has so far written applications for two major companies in the UK.
His other interests include simulation, on which he writes a weblog that takes up far
too much of his time, and thinking.

I’d like to thank Rick Ellis for writing CI and for making it available,
free. This spirit of generosity with such valuable intellectual
property is what makes the Open Source movement a success, and
an example to the rest of us.

I’d also like to thank Rick, and Derek Allard, for undertaking a
technical review of the book and making many helpful suggestions.

Mark Barker inspired and helped me to understand Object


Orientation, during many Saturday evening ‘geek-outs’.

Lastly, but not least, my thanks to Julia, John, and James for their
love, support, and patience.
About the Reviewers

Rick Ellis is the founder and CEO of EllisLab.com, the company that develops
CodeIgniter and several other widely used web applications. Rick Ellis has a diverse
background in media technology, having worked in creative and technical capacities
on interactive projects for Disney, to feature films for Oliver Stone, and almost every
kind of web-based project in-between.

Derek Allard is a programmer, author, and award-winning instructor based


in Toronto, Canada. He builds web applications, is a standards and accessibility
supporter, a scripting and database guy, and a PHP junkie. A sought-after educator
and freelancer, Derek spends most of his time working with XHTML, PHP, XML
and JavaScript.

As a highly visible CodeIgniter community member, Derek was hired by EllisLab as


the Senior Technical Support Specialist. He devotes time to ensuring CodeIgniter
and their flagship content management system, ExpressionEngine, remain
market leaders.

He blogs about all things web at www.derekallard.com.


Table of Contents
Preface 1
Chapter 1: Introduction to CodeIgniter 7
What can CodeIgniter Do for You? 7
Save Time 8
Make Your Site More Robust 9
Keep Your Links Up-To-Date Automatically 9
Save Database Crashes: 'prep' Your Data Entry Forms 10
Make Your Code Bolder 11
Send Email Attachments without Hassles 11
Save Bandwidth by Zipping Files That Users Need to Download 12
Yes, But…What is CodeIgniter? What are Frameworks? 12
And Who is That Man? 14
The 'Open Source' Business Model 15
What CI Doesn't Do 16
License 18
Summary 19
Chapter 2: Two Minutes' Work: Setting up a CodeIgniter Site 21
Prerequisites 21
Installing CodeIgniter 22
Exploring the File Structure 23
The Configuration File 24
Does it Work? 25
Summary 25
Chapter 3: Navigating Your Site 27
MVC—Just Another Acronym? 28
The Structure of a CI Site: Controllers and Views 29
The Welcome Controller 31
Working with Views 32
Table of Contents

The Default Controller 33


CodeIgniter Syntax Rules 33
Controller 34
View 34
Types of Files or Classes on a CI Site 34
What are All Those Folders For? 37
Designing a Better View 37
Designing a Better Controller 39
Getting Parameters to a Function 40
Passing Data to a View 41
How CI Classes Pass Information and Control to Each Other 43
Calling Views 43
Calling Functions Directly 43
Interacting with Controllers 44
It's Just Like an Egg-Cup 45
An Example of a CI Helper: the URL Helper 46
A Simple Library Example: Creating a Menu 48
Summary 49
Chapter 4: Using CI to Simplify Databases 51
Configuration Settings 51
Designing the Database for Our Site 52
Active Record 53
Advantages of Using the Active Record Class 54
Saving Time 54
Automatic Functionality 54
Read Queries 56
Displaying Query Results 58
Create and Update Queries 59
Delete Queries 61
Mixing Active Record and 'Classic' Styles 61
Summary 62
Chapter Appendix: MYSQL Query to Set Up 'websites' Database 63
Chapter 5: Simplifying HTML Pages and Forms 67
Writing a View 67
Long and Short PHP Syntax 69
Nesting Views 70
Practical Issues of Site Architecture 73
CI's Form Helper: Entering Data 74
Form Helper Advantage One: Clarity 74
Form Helper Advantage Two: Automation 77

[ ii ]
Table of Contents

My 'Display' Model 78
CI's Validation Class: Checking Data Easily 79
Set Up Validation 80
Set Up the Controller 81
Set Up the Forms 81
Summary 83
Chapter 6: Simplifying Sessions and Security 85
Starting to Design a Practical Site with CI 85
Moving Around the Site 86
Security/Sessions: Using Another CI Library Class 91
Turning Sessions into Security 94
Security 96
Summary 98
Chapter 7: CodeIgniter and Objects 99
Object-Oriented Programming 99
Working of the CI 'Super-Object' 100
Copying by Reference 103
Adding Your own Code to the CI 'Super-Object' 105
Problems with the CI 'Super-Object' 106
Summary 109
Chapter 8: Using CI to Test Code 111
Why Test, and What For? 111
CI's Error Handling Class 113
CI's Unit Test Class 115
When to Use Unit Tests 117
Example of a Unit Test 118
CI's Benchmarking Class 121
CI's Profiler Class 122
Testing with Mock Databases 123
Control and Timing 124
Summary 125
Chapter 9: Using CI to Communicate 127
Using the FTP Class to Test Remote Files 127
Machines Talking to Machines Again—XML-RPC 129
Getting the XML-RPC Server and Client in Touch with Each Other 131
Formatting XML-RPC Exchanges 132
Debugging 134
Issues with XML-RPC? 135
Talking to Humans for a Change: the Email Class 136
Summary 139

[ iii ]
Table of Contents

Chapter 10: How CI Helps to Provide Dynamic Information 141


The Date Helper: Converting and Localizing Dates 142
Working with Text: the Text Helper and Inflector Helper 145
Going International: the Language Class 146
Making HTML Tables the Easy Way: the Table Class 150
Caching Pages 152
Summary 154
Chapter 11: Using CI to Handle Files and Images 155
The File Helper 156
The Download Helper 158
The File Upload Class 160
CI's Image Class 165
Easy File Compression with the CI Zip Class 169
Summary 169
Chapter 12: Production Versions, Updates, and Big Decisions 171
Connections: Check the Config Files 172
URLs 172
Databases 172
Other config Files 173
Look Out for PHP 4/5 and Operating System Differences 173
Diagnostic Tools 174
Coping with Changes in New CI Versions 177
How to Load Models, and What to Call Them 178
How to Initialize Your Own 'library' Classes 179
So Should I Update If a New CI Version Comes Out? 179
How to Add On to CI's Basic Classes 181
Summary 183
Chapter 13: Instant CRUD—or Putting it All Together 185
The CRUD Model: Design Philosophy 186
The Standard Controller Format 187
The Database Tables 189
The Heart of the Model: the Array 189
Function by Function: the CRUD Model 192
Showall 192
Reading the Data 195
Delete and Trydelete 196
Insert 201
Insert2 208
The Test Suite 209
Summary 214

[ iv ]
Table of Contents

Chapter 14: The Verdict on CI 215


Some Code: the 'do_test' Model 216
A Balance Sheet 225
Where CI Helped: Structure 225
Where CI Helped: Simplicity 226
Where CI Helped: Extra Functionality 226
Problems with CI 226
Completeness 227
Ease of Use 227
Summary 228
Chapter 15: Resources and Extensions 229
CI's User Forums 230
Video Tutorials 232
Available Plug-ins and Libraries 232
AJAX/Javascript 233
Authentication 233
External Sites 235
Comparisons: Which Charting Library to Use? 235
CRUD: the Final Frontier 238
Resources for Other Programmes, e.g. Xampplite, MySQL, PHP 239
Summary 240
Index 241

[]
Preface
This book sets out to explain some of the main features of CI. It doesn't cover them
all, or cover any of them in full detail. CI comes with an excellent on-line User Guide
that explains most things. This is downloaded with the CI files.

This book doesn't try to duplicate the User Guide. Instead it tries to make it easier for
you to pick up how the CI framework works, so you can decide whether it is right
for you, and start using it quickly.

In some places, this book goes beyond the User Guide, though, when it tries to
explain how CI works. (The User Guide is more practically oriented.) This means
that there are some fairly theoretical chapters in between the "here's how" pages. I've
found that it helps to understand what CI is doing under the hood; otherwise you
sometimes get puzzling error messages that aren't easy to resolve.

I've tried to use a 'real-world' example when showing sections of CI code. I want
to show that CI can be used to develop a serious website with a serious purpose.
I'm currently running several websites for clients, and I want a program that will
monitor them, test them in ways I specify, keep a database of what it has done, and
let me have reports when I want them.

The examples in this book don't show it in full detail, of course: but they do, I hope,
demonstrate that you can use CI to make pretty well any common coding simpler,
and some uncommon stuff as well.

This book steps you through the main features of CodeIgniter in a systematic way,
explaining them clearly with illustrative code examples.
Preface

What This Book Covers


Chapter 1 explains what CodeIgniter can do, the 'framework', and how CodeIgniter
fits in. It further talks about the open-source business model and gives some
disadvantages of CodeIgniter, at the end.

Chapter 2 explains what happens when you install the site, and which files will be
created. It gives a detailed overview of the required software, and explains the basic
configuration of CodeIgniter.

Chapter 3 explains how MVC helps to organize a dynamic website. It goes further
to explain the process by which CodeIgniter analyzes an incoming Internet request
and decodes which part of your code will handle it. Then CodeIgniter syntax rules
and the different types of files or classes you can find—or write for yourself—on a
CodeIgniter site are explained. At the end of the chapter, some practical hints on site
design are given.

Chapter 4 looks at how you set up a database to work with CodeIgniter, and then
how you use the Active Record class to manipulate the database.

Chapter 5 covers various ways of building views, how to create HTML forms quickly,
and how to validate your forms using CodeIgniter's validation class.

Chapter 6 looks at one of the basic questions affecting any website i.e. session
management and security; we also explore CodeIgniter's session class.

Chapter 7 covers the way in which CodeIgniter uses objects, and the different ways in
which you can write and use your own objects.

Chapter 8 covers CodeIgniter classes to help with testing: Unit tests, Benchmarking,
the 'profiler' and ways in which CodeIgniter helps you to involve your database in
tests without scrambling live data.

Chapter 9 looks at using CodeIgniter's FTP class and email class to make
communication easier, and then we venture into Web 2.0 territory using XML-RPC.

Chapter 10 talks about CodeIgniter classes that help in overcoming problems arising
regularly when you are building a website, for example, the date helper, the text and
inflector helpers, the language class, and the table class.

Chapter 11 looks at several useful CodeIgniter functions and helpers: file helper,
download helper, file upload class, image manipulation class, and the ZIP class.

Chapter 12 covers exploring your config files, using diagnostic tools, and potential
differences between servers, along with some notes on security.

[]
Preface

Chapter 13 shows you how to generalize CRUD operations so that you can do them
with two classes: one for the controller, and one for the CRUD model.

Chapter 14 looks at some coding examples, bringing together a lot of the functions
that have been discussed bit by bit in the preceding chapters.

Chapter 15 looks at some of the resources available to you when you start to code
with CodeIgniter, such as the libraries for AJAX and JavaScript, authentication,
charting, and CRUD.

What You Need for This Book


Throughout this book, we will assume that you have the following packages
installed and available:

• PHP 4.3.2 or above


• A working web server
• One of MySQL, MySQLi, MS SQL, Postgre, Oracle, SQLite, ODBC

Conventions
In this book, you will find a number of styles of text that distinguish between
different kinds of information. Here are some examples of these styles, and an
explanation of their meaning.

There are three styles for code. Code words in text are shown as follows: "We can
include other contexts through the use of the include directive."

A block of code will be set as follows:


$active_group = "default";
$db['default']['hostname'] = "";
$db['default']['username'] = "";
$db['default']['password'] = "";

When we wish to draw your attention to a particular part of a code block, the
relevant lines or items will be made bold:
</head>
<body>
<h1 class='test'><?php echo $mytitle; ?> </h1>
<p class='test'><?php echo $mytext; ?> </p>
</body>

[]
Preface

New terms and important words are introduced in a bold-type font. Words that you
see on the screen, in menus or dialog boxes for example, appear in our text like this:
"clicking the Next button moves you to the next screen".

Warnings or important notes appear in a box like this.

Reader Feedback
Feedback from our readers is always welcome. Let us know what you think about
this book, what you liked or may have disliked. Reader feedback is important for us
to develop titles that you really get the most out of.

To send us general feedback, simply drop an email to [email protected],


making sure to mention the book title in the subject of your message.

If there is a book that you need and would like to see us publish, please send
us a note in the SUGGEST A TITLE form on www.packtpub.com or
email [email protected].

If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer Support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.

Downloading the Example Code for the


Book
Visit http://www.packtpub.com/support, and select this book from the list of titles
to download any example code or extra resources for this book. The files available
for download will then be displayed.

The downloadable files contain instructions on how to use them.

[]
Preface

Errata
Although we have taken every care to ensure the accuracy of our contents, mistakes
do happen. If you find a mistake in one of our books—maybe a mistake in text or
code—we would be grateful if you would report this to us. By doing this you can
save other readers from frustration, and help to improve subsequent versions of
this book. If you find any errata, report them by visiting http://www.packtpub.
com/support, selecting your book, clicking on the Submit Errata link, and entering
the details of your errata. Once your errata are verified, your submission will be
accepted and the errata added to the list of existing errata. The existing errata can be
viewed by selecting your title from http://www.packtpub.com/support.

Questions
You can contact us at [email protected] if you are having a problem with
some aspect of the book, and we will do our best to address it.

[]
Introduction to CodeIgniter
Most of us just want to write applications that work well, and to do it as simply and
easily as we can. This book is about CodeIgniter, a tool for making PHP easier to use.

If you need to produce results, if you think that the details and intricacies of coding
are for geeks, then you should look at CodeIgniter (CI to its friends).

CI is free, lightweight, and simple to install, and it really does make your life much
easier. Just read this chapter to find out how:

• What CI can do for you


• What is a 'framework' and how does CI fit in?
• The open-source business model
• Some disadvantages of CI (no, it's not perfect)

What can CodeIgniter Do for You?


If you are already writing code in PHP, CodeIgniter will help you to do it better, and
more easily. It will cut down on the amount of code you actually type. Your scripts
will be easier to read and update. It will help you to give large websites a coherent
structure. It will discipline your coding and make it more robust, in some cases
without you even knowing it.

That's quite a big claim. You have already spent some time learning PHP, HTML,
CSS, a database, and several other acronyms' worth of geek speak. You need a basic,
but not necessarily an expert, knowledge of PHP to benefit from CI.
Introduction to CodeIgniter

CodeIgniter is not for you if:

• You don't have a reasonable knowledge of PHP and HTML.


• You want to write a basic Content Management System (CMS) quickly and
simply, with a minimum of coding. (Look at a product like
Expression Engine.)
• You only want to write simple websites with a few standard features.

Save Time
CI doesn't take long to learn, and it quickly pays for your effort in the time saved
later on. Let's look at a simple measure:

How CI cuts down the amount of code you need to type.

This is not just good for the lazy. The less you type, the fewer mistakes you make,
and the less time you spend debugging your code. The smaller your code is, the
faster it loads and less space it takes up.

Here are two examples (which are explained later on in this book, so don't worry
now about how they work!).

Imagine you are writing a database query. This is how you might write a function
within your PHP programme to query a MySQL database:
$connection = mysql_connect("localhost","fred","12345");
mysql_select_db("websites", $connection);
$result = mysql_query ("SELECT * FROM sites", $connection);
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
foreach ($row as $attribute)
print "{$attribute[1]} ";
}

Now see how a CI function would handle a similar query:


$this->load->database('websites');
$query = $this->db->get('sites');
foreach ($query->result() as $row)
{
print $row->url
}

Compare the character counts: 244 for the traditional syntax; 112 for CI.

[]
Chapter 1

Now let's imagine that you are writing a data entry form in HTML, and you want
a drop-down query box. Let's say this drop-down query box shows three options
and allows the user to select one of them. In HTML, a drop-down box can be created
like this:
<select name="type">
<option value="1">www.this.com</option>
<option value="2">www.that.com</option>
<option value="3" selected>www.theother.com</option>
</select>

CI's version is both shorter and, because it works from an array, more adapted to
PHP processing:
$urlarray = array(
                  '1'  => 'www.this.com',
                  '2'  => 'www.that.com',
                  '3'  => 'www.theother.com',
                );

$variable .= form_dropdown('url', $urlarray, '1');

In HTML, you need to type 154 characters; in CI, 128.

Make Your Site More Robust


Although you don't need to write as much code, CI provides a lot of the standard
functionality for you, and remembers all those oddities and quirks. It keeps track
of things you may have forgotten all about. (Those little touches that distinguish
amateur sites from professional ones…)

Keep Your Links Up-To-Date Automatically


Imagine that you've just written a menu page, with lots of hyperlinks to other pages
in your site. They are all in the traditional HTML format:
<a href="http://www.mysite.com/index.php/start/hello/fred�
">say hello to Fred</a>

Then, you decide to move the site to another URL. That means you have to go
painstakingly through your code, looking for each URL, and re-writing it, or else
none of your links will work.

CI gives you a simple function to write hyperlinks like this:


echo anchor(start/hello/fred, Say hello to Fred);

[]
Introduction to CodeIgniter

CI also encourages you to put the URL of your site in a configuration file that the
rest of your site can access. CI's anchor function that we've used here automatically
refers to that configuration file. So, when you come to move your site, you only
need to change that one entry in the configuration file, and all your hyperlinks
update automatically.

Save Database Crashes: 'prep' Your Data Entry


Forms
Data entry is fraught with problems. Because of limitations of HTML and databases,
data that contain certain symbols— for example, apostrophes and quotation marks—
may cause your database to crash or to give results you did not expect.
The answer to this is to prepare or 'prep' your data in your data entry form, before it
is submitted to the database. All this takes time and a certain amount of extra coding.
CI's form helper does this, automatically. So, when you create an input box by typing:
echo form_input('username', 'johndoe');

You're also getting the hidden benefit of:


function form_prep($str = '')
{
if ($str === '')
{
return '';
}

$temp = '__TEMP_AMPERSANDS__';

// Replace entities to temporary markers so that


// htmlspecialchars won't mess them up
$str = preg_replace("/&#(\d+);/", "$temp\\1;", $str);
$str = preg_replace("/&(\w+);/", "$temp\\1;", $str);

$str = htmlspecialchars($str);

// In case htmlspecialchars misses these.


$str = str_replace(array("'", '"'), array("&#39;",
"&quot;"), $str);

// Decode the temp markers back to entities


$str = preg_replace("/$temp(\d+);/","&#\\1;",$str);
$str = preg_replace("/$temp(\w+);/","&\\1;",$str);

return $str;
}

[ 10 ]
Chapter 1

This is code that handles special characters like '&'; so that they don't cause confusion
while your form is being submitted. As you can see, there is some quite tricky regex
code in there.

Possibly you like typing out regexes. Some people like lying on beds of nails, some
like listening to ABBA; it's a free country. (Well, it is where I'm writing this.) But
if you don't like these things, you can let CI do them for you (the regexes, I mean,
not ABBA), and you needn't even be aware of the code that's working away in the
background for you, every time you write that one simple line of code:
echo form_input('username', 'johndoe');

Make Your Code Bolder


CI also makes it easy to do things you might not have tried before. Of course, PHP
users can always integrate libraries from PEAR and other sources, but these aren't
always easy to integrate, or use, and their syntax and standards differ greatly. CI has
a common set of standards, and once you've mastered its syntax, all its parts work
together without complication. All its code is well-written and reliable, and is tested
out by its user community. It puts much more sophistication in your hands.

Let's look at two examples to illustrate this point.

Send Email Attachments without Hassles


Sending emails is a complex business. CI's code for doing it looks easy to follow:
$this->load->library('email');
$this->email->from('[email protected]', 'Your Name');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();

There are a number of issues involved in sending emails: setting word-wrapping


(and escaping it so long URLs don't get wrapped and broken up) for example, or
sending attachments. The standard PHP functions can get quite complex here, and
the result is that many code writers are tempted to avoid using these functions if
they possibly can.

CI's email class makes it simple to send an attachment. You write:


$this->email->attach('/path/to/photo1.jpg');

CI does the rest. Working behind the scenes, for example, is a function that sorts out
MIME types for nearly hundred different types of attachment. So it knows that
your photo, photo1.jpg,��������������������������������������������������������
is an 'image/jpeg' MIME type. It remembers to generate

[ 11 ]
Introduction to CodeIgniter

boundary delimiters in the right places around your attachments. It takes care of
wrapping your text, and it allows you to easily mark out chunks of text you don't
want wrapped.

Save Bandwidth by Zipping Files That Users Need


to Download
To save bandwidth, it's a fairly common practice to compress or 'ZIP' files before
you download them. That's not something I've ever done, and I wouldn't know how
to go about it. On the other hand, CI has a nice facility that allows you to produce
zipped files with four lines of code:
$name = 'mydata1.txt';
$data = 'the contents of my file…………';
$this->zip->add_data($name, $data);
$this->zip->archive('c:/my_backup.zip');

Run this, and you find a ZIP archive on your C drive containing one file. Your ZIP
filer reader will unzip it and produce the original data for you.

People who use your site won't know that you've produced this impressive result
so easily. They'll be impressed! Your site will save bandwidth. You did it in minutes
rather than hours.

Yes, But…What is CodeIgniter? What are


Frameworks?
Shortly after programming was invented, someone noticed that it involved many
repetitive operations. And shortly after that, someone else—maybe it was Ada
Lovelace, spanner in hand, adjusting Babbage's differential engine, or maybe it was
Alan Turing at Bletchley Park—decided to modularize code, so you only had to
write certain chunks once, and could then re-use them. PHP programmers are used
to writing separate chunks of code in functions, and then storing those functions in
include files.

At one level, a framework is just that: lots of chunks of code, stored in separate files,
which simplify the coding of repetitive operations.

[ 12 ]
Another Random Document on
Scribd Without Any Related Topics
our children; we will keep the dogs from eating your bones, which are so
hard.”694

The elan, deer, and elk were treated by the American Indians with the same
punctilious respect, and for the same [pg 241] reason. Their bones might
not be given to the dogs nor thrown into the fire, nor might their fat be
dropped upon the fire, because the souls of the dead animals were believed
to see what was done to their bodies and to tell it to the other beasts, living
and dead. Hence, if their bodies were ill-used, the animals of that species
would not allow themselves to be taken, neither in this world nor in the
world to come.695 The houses of the Indians of Honduras were encumbered
with the bones of deer, the Indians believing that if they threw the bones
away, the other deer could not be taken.696 Among the Chiquites of
Paraguay a sick man would be asked by the medicine-man whether he had
not thrown away some of the flesh of the deer or turtle, and if he answered
yes, the medicine-man would say, “That is what is killing you. The soul of
the deer or turtle has entered into your body to avenge the wrong you did
it.”697 Before the Tzentales of Southern Mexico and the Kekchis of Guatemala
venture to skin a deer which they have killed, they lift up its head and burn
copal before it as an offering; otherwise a certain being named Tzultacca
would be angry and send them no more game.698 Cherokee hunters ask
pardon of the deer they kill. If they failed to do so, they think that the Little
Deer, the chief of the deer tribe, who can never die or be wounded, would
track the hunter to his home by the blood-drops on the ground and would
put the spirit of rheumatism into him. Sometimes the hunter, on starting for
home, lights a fire in the trail behind him to prevent the Little Deer from
pursuing him.699 Before they [pg 242] went out to hunt for deer, antelope,
or elk the Apaches used to resort to sacred caves, where the medicine-men
propitiated with prayer and sacrifice the animal gods whose progeny they
intended to destroy.700 The Indians of Louisiana bewailed bitterly the death
of the buffaloes which they were about to kill. More than two hundred of
them at a time have been seen shedding crocodile tears over the
approaching slaughter of the animals, while they marched in solemn
procession, headed by an old man who waved a pocket-handkerchief at the
end of a stick as an oriflamme, and by a woman who strutted proudly along,
bearing on her back a large kettle which had been recently abstracted from
the baggage of some French explorers.701 The Thompson Indians of British
Columbia cherished many superstitious beliefs and observed many
superstitious practices in regard to deer. When a deer was killed, they said
that the rest of the deer would be well pleased if the hunters butchered the
animal nicely and cleanly. To waste venison displeased the animals, who
after that would not allow themselves to be shot by the hunter. If a hunter
was overburdened and had to leave some of the venison behind, the other
deer were better pleased if he hung it up on a tree than if he let it lie on the
ground. The guts were gathered and put where the blood had been spilt in
butchering the beast, and the whole was covered up with a few fir-boughs.
In laying the boughs on the blood and guts the man told the deer not to
grieve for the death of their friend and not to take it ill that he had left some
of the body behind, for he had done his best to cover it. If he did not cover
it, they thought the deer would be sorry or angry and would spoil his luck in
the chase. When the head of a deer had to be left behind, they commonly
placed it on the branch of a tree, that it might not be contaminated by dogs
and women. For the same reason they burned the bones of the slain deer,
lest they should be touched by women or gnawed by dogs. And venison was
never brought into a hut by the common door, because that door was used
by women; it was taken in [pg 243] through a hole made in the back of the
hut. No hunter would give a deer's head to a man who was the first or
second of a family, for that would make the rest of the deer very shy and
hard to shoot. And in telling his friends of his bag he would generally call a
buck a doe, and a doe he would call a fawn, and a fawn he would call a
hare. This he did that he might not seem to the deer to brag.702 The Lillooet
Indians of British Columbia threw the bones of animals, particularly those of
the deer and the beaver, into the water, in order that the dogs should not
defile or eat them and thereby offend the animals. When the hunter
committed the bones to the water he generally prayed to the dead animal,
saying, “See! I treat you respectfully. Nothing shall defile you. Have pity on
me, so I may kill more of you! May I be successful in hunting and
trapping!”703 The Canadian Indians would not eat the embryos of the elk,
unless at the close of the hunting season; otherwise the mother-elks would
be shy and refuse to be caught.704

Indians of the Lower Fraser River regard the porcupine as their elder
brother. Hence when a hunter kills one of these creatures he asks his elder
brother's pardon and does not eat of the flesh till the next day.705 The Sioux
will not stick an awl or needle into a turtle, for they are sure that, if they
were to do so, the turtle would punish them at some future time.706 Some of
the North American Indians believed that each sort of animal had its patron
or genius who watched over and preserved it. An Indian girl having once
picked up a dead mouse, her father snatched the little creature from her
and tenderly caressed and fondled it. Being asked why he did so, he said
that it was to appease the genius of mice, in order that he might not
torment his daughter for eating the [pg 244] mouse. With that he handed
the mouse to the girl and she ate it.707

When the Koryak have killed a fox, they take the body home and lay it down
near the fire, saying, “Let the guest warm himself. When he feels warm, we
will free him from his overcoat.” So when the frozen carcase is thawed, they
skin it and wrap long strips of grass round about it. Then the animal's mouth
is filled with fish-roe, and the mistress of the house gashes the flesh and
puts more roe or dried meat into the gashes, making believe that the
gashes are the fox's pockets, which she thus fills with provisions. Then the
carcase is carried out of the house, and the people say, “Go and tell your
friends that it is good to visit yonder house. ‘Instead of my old coat, they
gave me a new one still warmer and with longer hair. I have eaten my fill,
and had my pockets well stored. You, too, go and visit them.’ ” The natives
think that if they neglected to observe this ceremonial they would have no
luck in hunting foxes.708 When a Ewe hunter of Togoland has killed an
antelope of a particular kind (Antilope leucoryx), he erects an enclosure of
branches, within which he places the lower jawbones of all the animals he
has shot. Then he pours palm-wine and sprinkles meal on the bones,
saying, “Ye lower jawbones of beasts, ye are now come home. Here is food,
here is drink. Therefore lead your comrades (that is, the living beasts of the
forest) hither also.”709 In the Timor-laut islands of the Indian Archipelago the
skulls of all the turtles which a fisherman has caught are hung up under his
house. Before he goes out to catch another, he addresses himself to the
skull of the last turtle that he killed, and having inserted betel between its
jaws, he prays the spirit of the dead animal to entice its kinsfolk in the sea
to come and be caught.710 In the Poso district of central Celebes hunters
keep the jawbones of deer and wild pigs which they have killed and hang
them up in their houses near the fire. Then they say [pg 245] to the
jawbones, “Ye cry after your comrades, that your grandfathers, or nephews,
or children may not go away.” Their notion is that the souls of the dead deer
and pigs tarry near their jawbones and attract the souls of living deer and
pigs, which are thus drawn into the toils of the hunter.711 Thus in all these
cases the wily savage employs dead animals as decoys to lure living animals
to their doom.
The Lengua Indians of the Gran Chaco love to hunt the ostrich, but when
they have killed one of these birds and are bringing home the carcase to the
f village, they take steps to outwit the resentful ghost of their victim. They
think that when the first natural shock of death is passed, the ghost of the
ostrich pulls himself together and makes after his body. Acting on this sage
calculation, the Indians pluck feathers from the breast of the bird and strew
them at intervals along the track. At every bunch of feathers the ghost stops
to consider, “Is this the whole of my body or only a part of it?” The doubt
gives him pause, and when at last he has made up his mind fully at all the
bunches, and has further wasted valuable time by the zigzag course which
he invariably pursues in going from one to another, the hunters are safe at
home, and the bilked ghost may stalk in vain round about the village, which
he is too timid to enter.712

The Esquimaux of the Hudson Bay region believe that the reindeer are
controlled by a great spirit who resides in a large cave near the end of Cape
Chidley. The outward form of the spirit is that of a huge white bear. He
obtains and controls the spirit of every reindeer that is slain or dies, and it
depends on his good will whether the people shall have a supply of reindeer
or not. The sorcerer intercedes with this great spirit and prevails on him to
send the deer to the hungry Esquimaux. He informs the spirit that the
people have in no way offended him, since he, the sorcerer, has taken great
care that the whole of the meat was eaten up, [pg 246] and that last spring,
when the does were returning to him to drop their young, none of the little
or embryo fawns were devoured by the dogs. After long incantations the
magician announces that the patron of the deer condescends to supply the
Esquimaux with the spirits of the animals in a material form, and that soon
there will be plenty in the land. He charges the people to fall on and slay
and thereby win the approval of the spirit, who loves to see good folk
enjoying themselves, knowing that so long as the Esquimaux refrain from
feeding their dogs with the unborn young, the spirits of the dead reindeer
will return again to his watchful care. The dogs are not allowed to taste the
flesh, and until the supply is plentiful they may not gnaw the leg-bones, lest
the guardian of the deer should take offence and send no more of the
animals. If, unfortunately, a dog should get at the meat, a piece of his tail is
cut off or his ear is cropped to let the blood flow.713 Again, the Central
Esquimaux hold that sea-mammals, particularly whales, ground-seals, and
common seals, sprang from the severed fingers of the goddess Sedna, and
that therefore an Esquimau must make atonement for every such animal
that he kills. When a seal is brought into the hut, the woman must stop
working till it has been cut up. After the capture of a ground seal, walrus, or
whale they must rest for three days. Not all sorts of work, however, are
forbidden, for they may mend articles made of sealskin, but they may not
make anything new. For example, an old tent cover may be enlarged in
order to build a larger hut, but it is not allowed to make a new one. Working
on new deerskins is strictly forbidden. No skins of this kind obtained in
summer may be prepared before the ice has formed and the first seal has
been caught with the harpoon. Later on, as soon as the first walrus has
been taken, the work must again stop until autumn comes round. Hence all
families are eager to finish the work on deerskins as fast as possible, for
until that is done the walrus season may not begin.714 The Greenlanders are
careful not to [pg 247] fracture the heads of seals or throw them into the
sea, but pile them in a heap before the door, that the souls of the seals may
not be enraged and scare their brethren from the coast.715

The Esquimaux about Bering Strait believe that the souls of dead sea-
beasts, such as seals, walrus, and whales, remain attached to their
bladders, and that by returning the bladders to the sea they can cause the
souls to be reincarnated in fresh bodies and so multiply the game which the
hunters pursue and kill. Acting on this belief every hunter carefully removes
and preserves the bladders of all the sea-beasts that he kills; and at a
solemn festival held once a year in winter these bladders, containing the
souls of all the sea-beasts that have been killed throughout the year, are
honoured with dances and offerings of food in the public assembly-room,
after which they are taken out on the ice and thrust through holes into the
water; for the simple Esquimaux imagine that the souls of the animals, in
high good humour at the kind treatment they have experienced, will
thereafter be born again as seals, walrus, and whales, and in that form will
flock willingly to be again speared, harpooned, or otherwise done to death
by the hunters. The ceremonies observed at these annual festivals of
reincarnation are elaborate. The assembly-room or dancing-house (kashim,
kassigim, or kassigit), in which the festival is held, consists of a spacious
semi-subterranean chamber entered by a tunnel, which leads down to a
large round cellar under the floor of the house. From the cellar you ascend
into the assembly-room through a hole in the floor. Wooden benches run
round the apartment, which is lit by lamps. An opening in the roof serves at
once as a window and a chimney. Unmarried men sleep in the assembly-
room at all times; they have no other home. The festival is commonly held
in December, but it may fall as late as January. It lasts several days. When
the time is come [pg 248] to celebrate it, each hunter brings into the
assembly-room the inflated bladders of all the seals, walrus, and whales that
he has killed during the year. These are tied by the necks in bunches and
hung up on seal spears, which are stuck in a row in the wall some six or
eight feet above the floor. Here food and water are offered to them, or
rather to the spirits of the animals which are supposed to be present in the
bladders; and the spirits signify their acceptance of the offering by causing
the bladders to swing to and fro, a movement which is really produced by a
man sitting in a dark corner, who pulls a string attached to the bladders.
Further, the bladders are fumigated with torches of wild parsnip stalks, the
aromatic smoke and red flames of which are believed to be well-pleasing to
the souls of the animals dangling in the bladders. Moreover to amuse the
souls men execute curious dances before them to the music of drums. First
the dancers move slowly with a jerky action from side to side; then they
gallop obliquely with arms tossed up and down; and lastly they hop and
jump, always keeping perfect time to the beat of the drums. The dance is
supposed to imitate the movements of seals and walrus; and again the
spirits signify their pleasure by making the bladders swing backwards and
forwards. During the continuance of the festival no loud noises may be
made in the assembly-room for fear of alarming the souls of the animals in
the bladders; if any person makes a noise by accident, all the men present
raise a chorus of cries in imitation of the notes of the eider duck to let the
souls of the animals think that the unseemly disturbance proceeds from the
birds and not from the people. Further, so long as the festival lasts, no wood
may be cut with an iron axe in the village, the men must keep rigidly apart
from the women, and no female above the age of puberty may come near
the bladders suspended in the assembly-room, the reason assigned being
that such women are unclean and might offend the sensitive souls of the
sea-beasts in the bladders. But immature girls, being untainted by the
pollution which attaches to adult women, may go about the bladders freely.
The last and crowning scene of the festival takes place at night or just at
sunrise. The spears [pg 249] with the bladders attached to them are passed
out by the shaman into the open air through the smoke-hole in the roof.
When all are outside, a huge torch of wild parsnip stalks is lighted; the chief
shaman takes it on his shoulder, and runs with it as fast as he can across
the snow and out on the ice. Behind him troop all the men carrying each his
spear with the bladders of the sea-beasts dangling and flapping from it; and
in the rear race the women, children, and old men, howling, screaming and
making a great uproar. In the darkness the lurid flame of the torch shoots
high into the air, casting a red glare over the snowy landscape and lighting
up the swarm of fantastic, fur-clad figures that stream along in wild
excitement. Arrived at a hole, which had been cut on purpose in the sea-ice,
the shaman plants his burning torch beside it in the snow, and every man as
he comes up rips open his bladders and thrusts them, one after the other,
into the water under the ice. This ends the ceremony. The souls of the dead
seals, walrus, and whales, are now ready to be born again in the depths of
the sea. So all the people return contented to the village. At St. Michael the
men who have thrust the bladders under the ice are obliged on their return
to leap through a fire of wild parsnip stalks, probably as a mode of
ceremonial purification; for after the dance and the offering of food at the
festival the chief shaman passes a lighted torch of parsnip stalks round the
assembly-room and the dancers, for the express purpose of purifying them
and averting any evil influence that might bring sickness or ill luck on the
hunters.716

For like reasons, a tribe which depends for its subsistence, chiefly or in part,
upon fishing is careful to treat the fish with every mark of honour and
respect. The Indians of Peru “worshipped the whale for its monstrous
greatness. Besides this ordinary system of worship, which prevailed [pg
250] throughout the coast, the people of different provinces adored the fish
that they caught in greatest abundance; for they said that the first fish that
was made in the world above (for so they named Heaven) gave birth to all
other fish of that species, and took care to send them plenty of its children
to sustain their tribe. For this reason they worshipped sardines in one
region, where they killed more of them than of any other fish; in others, the
skate; in others, the dogfish; in others, the golden fish for its beauty; in
others, the crawfish; in others, for want of larger gods, the crabs, where
they had no other fish, or where they knew not how to catch and kill them.
In short, they had whatever fish was most serviceable to them as their
f
gods.”717 The Kwakiutl Indians of British Columbia think that when a salmon
is killed its soul returns to the salmon country. Hence they take care to
throw the bones and offal into the sea, in order that the soul may reanimate
them at the resurrection of the salmon. Whereas if they burned the bones
the soul would be lost, and so it would be quite impossible for that salmon
to rise from the dead.718 In like manner the Otawa Indians of Canada,
believing that the souls of dead fish passed into other bodies of fish, never
burned fish bones, for fear of displeasing the souls of the fish, who would
come no more to the nets.719 The Hurons also refrained from throwing fish
bones into the fire, lest the souls of the fish should go and warn the other
fish not to let themselves be caught, since the Hurons would burn their
bones. Moreover, they had men who preached to the fish and persuaded
them to come and be caught. A good preacher was much sought after, for
they thought that the exhortations of a clever man had a great effect in
drawing the fish to the nets. In the Huron fishing village where the French
missionary Sagard stayed, the preacher to the [pg 251] fish prided himself
very much on his eloquence, which was of a florid order. Every evening after
supper, having seen that all the people were in their places and that a strict
silence was observed, he preached to the fish. His text was that the Hurons
did not burn fish bones. “Then enlarging on this theme with extraordinary
unction, he exhorted and conjured and invited and implored the fish to
come and be caught and to be of good courage and to fear nothing, for it
was all to serve their friends who honoured them and did not burn their
bones.”720 At Bogadjim in German New Guinea an enchanter is employed to
lure the fish to their doom. He stands in a canoe on the beach with a
decorated fish-basket beside him, and commands the fish to come from all
quarters to Bogadjim.721 When the Aino have killed a sword-fish, they thank
the fish for allowing himself to be caught and invite him to come again.722
Among the Nootka Indians of British Columbia it was formerly a rule that
any person who had partaken of bear's flesh must rigidly abstain from
eating any kind of fish for a term of two months. The motive for the
abstinence was not any consideration for the health of the eater, but “a
superstitious belief, that should any of their people after tasting bear's flesh,
eat of fresh salmon, cod, etc., the fish, though at ever so great a distance
off, would come to the knowledge of it, and be so much offended thereat,
as not to allow themselves to be taken by any of the inhabitants.”723 The
disappearance of herring from the sea about Heligoland in 1530 was
attributed by the fishermen to the misconduct of two lads who had whipped
a freshly-caught herring and then flung it back into the sea.724 A similar
disappearance of the herrings from the Moray Firth, in the reign of Queen
Anne, was set down by some people to a breach of the Sabbath which had
been committed by the fishermen, while others opined that it was due to a
quarrel [pg 252] in which blood had been spilt in the sea.725 For Scotch
fishermen are persuaded that if blood be drawn in a quarrel on the coast
where herring are being caught, the shoal will at once take its departure
and not return for that season at least. West Highland fishermen believe
that every shoal of herring has its leader which it follows wherever he goes.
This leader is twice as big as an ordinary herring, and the fishermen call it
the king of herring. When they chance to catch it in their nets they put it
back carefully into the sea; for they would esteem it petty treason to
destroy the royal fish.726 The natives of the Duke of York Island annually
decorate a canoe with flowers and ferns, lade it, or are supposed to lade it,
with shell-money, and set it adrift to compensate the fish for their fellows
who have been caught and eaten.727 When the Tarahumares of Mexico are
preparing to poison the waters of a river for the purpose of stupefying and
catching the fish, they take the precaution of first making offerings to the
Master of the Fish by way of payment for the fish of which they are about to
bereave him. The offerings consist of axes, hats, blankets, girdles, pouches,
and especially knives and strings of beads, which are hung to a cross or a
horizontal bar set up in the middle of the river. However, the Master of the
Fish, who is thought to be the oldest fish, does not long enjoy these good
things; for next morning the owners of the various articles remove them
from the river and appropriate them to their usual secular purposes.728 It is
especially necessary to treat the first fish caught with consideration in order
to conciliate the rest of the fish, whose conduct may be supposed to be
influenced by the reception given to those of their kind which were the first
to be taken. Accordingly the Maoris always put back into the sea the first
fish caught, “with a prayer that it may tempt other fish to come and be
caught.”729 Among the Baganda “the first fish taken were [pg 253] treated
ceremonially: some the fisherman took to the god Mukasa; the remainder
his wife cooked, and he and she both partook of them, and he afterwards
jumped over her.”730

Still more stringent are the precautions taken when the fish are the first of
the season. On salmon rivers, when the fish begin to run up the stream in
spring, they are received with much deference by tribes who, like the
Indians of the Pacific Coast of North America, subsist largely upon a fish
diet. To some of these tribes the salmon is what corn is to the European,
rice to the Chinese, and seals to the Esquimaux. Plenty of salmon means
abundance in the camp and joy at the domestic hearth; failure of the
salmon for a single season means famine and desolation, silence in the
village, and sad hearts about the fire.731 Accordingly in British Columbia the
Indians used to go out to meet the first fish as they came up the river:
“They paid court to them, and would address them thus: ‘You fish, you fish;
you are all chiefs, you are; you are all chiefs.’ ”732 Amongst the Thlinkeet or
Tlingit of Alaska the first halibut of the season is carefully handled and
addressed as a chief, and a festival is given in his honour, after which the
fishing goes on.733 Among the tribes of the Lower Fraser River when the first
sockeye-salmon of the season has been caught, the fisherman carries it to
the chief of his tribe, who delivers it to his wife. She prays, saying to the
salmon, “Who has brought you here to make us happy? We are thankful to
your chief for sending you.” When she has cut and roasted the salmon
according to certain prescribed rules, the whole tribe is invited and partakes
of the fish, after they have purified themselves by drinking a decoction of
certain plants which is regarded as a medicine for cleansing the people. But
widowers, widows, menstruous women, and youths may not eat of this
particular salmon. Even later, when the fish have become plentiful and these
ceremonies are dispensed with, the same classes of [pg 254] persons are
not allowed to eat fresh salmon, though they may partake of the dried fish.
The sockeye-salmon must always be looked after carefully. Its bones have
to be thrown into the river, after which the fish will revive and return to its
chief in the west. Whereas if the fish are not treated with consideration,
they will take their revenge, and the careless fisherman will be unlucky.734
Among the Songish or Lkungen tribe of Vancouver Island it is a rule that on
the day when the first salmon have been caught, the children must stand on
the beach waiting for the boats to return. They stretch out their little arms
and the salmon are heaped on them, the heads of the fish being always
kept in the direction in which the salmon are swimming, else they would
cease to run up the river. So the children carry them and lay them on a
grassy place, carefully keeping the heads of the salmon turned in the same
direction. Round the fish are placed four flat stones, on which the plant
hog's wort (Peucedanum leiocarpum, Nutt.), red paint, and bulrushes are
burnt as an offering to the salmon. When the salmon have been roasted
each of the children receives one, which he or she is obliged to eat, leaving
nothing over. But grown people are not allowed to eat the fish for several
days. The bones of the salmon that the children have eaten may not touch
the ground. They are kept in dishes, and on the fourth day an old woman,
who pretends to be lame, gathers them in a huge basket and throws them
into the sea.735 The Tsimshian Indians of British Columbia observe certain
ceremonies when the first olachen fish of the season are caught. The fish
are roasted on an instrument of elder-berry wood, and the man who roasts
them must wear his travelling dress, mittens, cape, and so forth. While this
is being done the Indians pray that plenty of olachen may come to their
fishing-ground. The fire may not be blown up, and in eating the fish they
[pg 255] may not cool it by blowing nor break a single bone. Everything
must be neat and clean, and the rakes used for catching the fish must be
kept hidden in the house.736 In spring, when the winds blow soft from the
south and the salmon begin to run up the Klamath river, the Karoks of
California dance for salmon, to ensure a good catch. One of the Indians,
called the Kareya or God-man, retires to the mountains and fasts for ten
days. On his return the people flee, while he goes to the river, takes the first
salmon of the catch, eats some of it, and with the rest kindles the sacred
fire in the sweating-house. “No Indian may take a salmon before this dance
is held, nor for ten days after it, even if his family are starving.” The Karoks
also believe that a fisherman will take no salmon if the poles of which his
spearing-booth is made were gathered on the river-side, where the salmon
might have seen them. The poles must be brought from the top of the
highest mountain. The fisherman will also labour in vain if he uses the same
poles a second year in booths or weirs, “because the old salmon will have
told the young ones about them.”737 Among the Indians of the Columbia
River, “when the salmon make their first appearance in the river, they are
never allowed to be cut crosswise, nor boiled, but roasted; nor are they
allowed to be sold without the heart being first taken out, nor to be kept
over night, but must be all consumed or eaten the day they are taken out of
the water. All these rules are observed for about ten days.”738 They think
that if the heart of a fish were eaten by a stranger at the beginning of the
season, they would catch no more fish. Hence, they roast and eat the hearts
themselves.739 There is a favourite fish of the Aino which appears in their
rivers about May and June. They prepare for the fishing by observing rules
of ceremonial purity, and when they have gone out to fish, the women at
[pg 256] home must keep strict silence or the fish would hear them and
disappear. When the first fish is caught he is brought home and passed
through a small opening at the end of the hut, but not through the door; for
if he were passed through the door, “the other fish would certainly see him
and disappear.”740 This may partly explain the custom observed by other
savages of bringing game in certain cases into their huts, not by the door,
but by the window, the smoke-hole, or by a special opening at the back of
the hut.741

With some savages a special reason for respecting the bones of game, and
generally of the animals which they eat, is a belief that, if the bones are
preserved, they will in course of time be reclothed with flesh, and thus the
animal will come to life again. It is, therefore, clearly for the interest of the
hunter to leave the bones intact, since to destroy them would be to diminish
the future supply of game. Many of the Minnetaree Indians “believe that the
bones of those bisons which they have slain and divested of flesh rise again
clothed with renewed flesh, and quickened with life, and become fat, and fit
for slaughter the succeeding June.”742 Hence on the western prairies of
America, the skulls of buffaloes may be seen arranged in circles and
symmetrical piles, awaiting the resurrection.743 After feasting on a dog, the
Dacotas carefully collect the bones, scrape, wash, and bury them, “partly, as
it is said, to testify to the dog-species, that in feasting upon one of their
number no disrespect was meant to the species itself, and partly also from
[pg 257] a belief that the bones of the animal will rise and reproduce
another.”744 Among the Esquimaux of Baffin Land and Hudson Bay, when a
boy has killed his first seal, his mother gathers all the bones and throws
them into a seal-hole. They think that these bones will become seals which
the boy will catch in later life.745 The Yuracares Indians of Bolivia are at
great pains to collect all the bones of the beasts, birds, and fishes which
they eat, and to throw them into a stream, bury them in the depths of the
forest, or burn them in the fire, “in order that the animals of the sort killed
may not be angry and may allow themselves to be killed again.”746 In
sacrificing an animal the Lapps regularly put aside the bones, eyes, ears,
heart, lungs, sexual parts (if the animal was a male), and a morsel of flesh
from each limb. Then, after eating the remainder of the flesh, they laid the
bones and the rest in anatomical order in a coffin and buried them with the
usual rites, believing that the god to whom the animal was sacrificed would
reclothe the bones with flesh and restore the animal to life in Jabme-Aimo,
the subterranean world of the dead. Sometimes, as after feasting on a bear,
they seem to have contented themselves with thus burying the bones.747
Thus the Lapps expected the resurrection of the slain animal to take place in
another world, resembling in this respect the Kamtchatkans, who believed
that every creature, down to the smallest fly, would rise from the dead and
live underground.748 On the other hand, the North American Indians looked
for the resurrection of the animals in the present world. The habit, observed
especially by Mongolian peoples, of stuffing the skin of a sacrificed [pg 258]
animal, or stretching it on a framework,749 points rather to a belief in a
resurrection of the latter sort. The objection commonly entertained by
primitive peoples to break the bones of the animals which they have eaten
or sacrificed750 [pg 259] may be based either on a belief in the resurrection
of the animals, or on a fear of intimidating other creatures of the same
species and offending the ghosts of the slain animals. The reluctance of
North American Indians and Esquimaux to let dogs gnaw the bones of
animals751 is perhaps only a precaution to prevent the bones from being
broken.

We have already seen that some rude races believe in a resurrection of


men752 as well as of beasts, and it is quite natural that people who entertain
such a belief should take care of the bones of their dead in order that the
original owners of the bones may have them to hand at the critical moment.
Hence in the Mexican territories of Guazacualco and Yluta, where the
Indians thought that the dead would rise again, the bones of the departed
were deposited in baskets and hung up on trees, that their spirits might not
be obliged to grub in the earth for them at the resurrection.753 [pg 260] On
the other hand, the Luritcha tribe of Central Australia, who eat their
enemies, take steps to prevent their coming to life again, which might prove
very inconvenient, by destroying the bones and especially the skulls of the
bodies on which they have banqueted.754

The preceding review of customs observed by savages for the conciliation


and multiplication of animals which they hunt and kill, is fitted to impress us
with a lively sense of the unquestioning faith which primitive man reposes in
the immortality of the lower creatures. He appears to assume as an axiom
too obvious to be disputed that beasts, birds, and fishes have souls like his
own, which survive the death of their bodies and can be reborn in other
bodies to be again killed and eaten by the hunter. The whole series of
customs described in the foregoing pages—customs which are apt to strike
f the civilised reader as quaint and absurd—rests on this fundamental
assumption. A consideration of them suggests a doubt whether the current
explanation of the savage belief in human immortality is adequate to
account for all the facts. That belief is commonly deduced from a primitive
theory of dreams. The savage, it is said, fails to distinguish the visions of
sleep from the realities of waking life, and accordingly when he has
dreamed of his dead friends he necessarily concludes that they have not
wholly perished, but that their spirits continue to exist in some place and
some form, though in the ordinary course of events they elude the
perceptions of his senses. On this theory the conceptions, whether gross or
refined, whether repulsive or beautiful, which savages and perhaps civilised
men have formed of the state of the departed, would seem to be no more
than elaborate hypotheses constructed to account for appearances in
dreams; these towering structures, for all their radiant or gloomy grandeur,
for all the massy strength and solidity with which they present themselves
f to the imagination of many, may turn out on inspection to be mere visionary
castles built of clouds and vapour, which a breath of reason suffices to melt
into air.

[pg 261]

But even if we grant for the sake of argument that this theory offers a ready
explanation of the widespread belief in human immortality, it is less easy to
see how the theory accounts for the corresponding belief of so many races
f in the immortality of the lower animals. In his dreams the savage recognises
the images of his departed friends by those familiar traits of feature, voice,
and gesture which characterised them in life. But can we suppose that he
recognises dead beasts, birds, and fishes in like manner? That their images
come before him in sleep with all the particular features, the minute
individual differences, which distinguished them in life from their fellows, so
that when he sees them he can say to himself, for example, “This is the very
tiger that I speared yesterday; his carcase is dead, but his spirit must be still
f alive”; or, “That is the very salmon I caught and ate this morning; I certainly
killed his body but clearly I have not succeeded in destroying his soul”? No
doubt it is possible that the savage has arrived at his theory of animal
immortality by some such process of reasoning, but the supposition seems
at least more far-fetched and improbable than in the case of human
immortality. And if we admit the insufficiency of the explanation in the one
case, we seem bound to admit it, though perhaps in a less degree, in the
other case also. In short, we conclude that the theory of dreams appears to
be hardly enough by itself to account for the widespread belief in the
immortality of men and animals; dreams have probably done much to
confirm that belief, but would they suffice to originate it? We may
reasonably doubt it.

Accordingly we are driven to cast about for some more adequate


explanation of this prevalent and deeply rooted persuasion. In search of
such an explanation perhaps we need go no further than the sense of life
which every man feels in his own breast.755 We have seen that to the savage
death presents itself not as a natural necessity but as a lamentable accident
or crime that cuts short an existence which, but for it, might have lasted for
ever.756 Thus arguing apparently from his own sensations he conceives of life
as an indestructible [pg 262] kind of energy, which when it disappears in
one form must necessarily reappear in another, though in the new form it
need not be immediately perceptible by us; in other words, he infers that
death does not destroy the vital principle nor even the conscious personality,
but that it merely transforms both of them into other shapes, which are not
the less real because they commonly elude the evidence of our senses. If I
am right in thus interpreting the thought of primitive man, the savage view
of the nature of life singularly resembles the modern scientific doctrine of
the conservation of energy. According to that doctrine, no material energy
ever perishes or is even diminished; when it seems to suffer diminution or
extinction, all that happens is that a portion or the whole of it has been
transmuted into other shapes which, though qualitatively different from, are
f quantitatively equivalent to, the energy in its original form. In short, if we
listen to science, nothing in the physical world is ever lost, but all things are
perpetually changing: the sum of energy in the universe is constant and
invariable, though it undergoes ceaseless transformations.757 A similar
theory of the indestructibility of energy is implicitly applied by the savage to
explain the phenomena of life and death, and logically enough he does not
limit the application to human beings but extends it to the lower animals.
Therein he shews himself a better reasoner than his civilised brother, who
commonly embraces with avidity the doctrine of human immortality but
rejects with scorn, as derogatory to human dignity, the idea that animals
have immortal souls. And when he attempts to confirm his own cherished
belief in a life after death by appealing to similar beliefs among savages and
inferring from them a natural instinct of immortality, it is well to [pg 263]
remind him that, if he stands by that appeal, he must, like the savage,
consistently extend the privilege of immortality to the despised lower
animals; for surely it is improper for him to pick and choose his evidence so
as to suit his prepossessions, accepting those parts of the savage creed
which tally with his own and rejecting those which do not. On logical and
scientific grounds he seems bound to believe either more or less: he must
hold that men and animals are alike immortal or that neither of them is so.

We have seen that many savages look forward to a joyful resurrection of


men and beasts, if only a proper care is taken of their skeletons; the same
old bones, they imagine, will do duty over again in the next life, when they
have been decently clad in a new garment of flesh. This quaint fancy is
reflected in many popular tales; not uncommonly the animal or man in the
story comes to life lame of a limb, because one of his bones has been
eaten, broken, or lost.758 In a Magyar tale, the hero is cut in pieces, but the
serpent-king lays the bones together in their proper order, and washes them
with water, whereupon the hero revives. His shoulder-blade, however, has
been lost, so the serpent-king supplies its place with one of gold and
ivory.759 Such stories, as Mannhardt has seen, explain why Pythagoras, who
claimed to have lived many lives, one after the other, was said to have
exhibited his golden leg as a proof of his supernatural pretensions.760
Doubtless he explained that at one of his resurrections a leg had been
broken or mislaid, and that he had replaced it, like Miss Kilmansegg, with
one of gold. Similarly, when the murdered Pelops was restored to life, the
shoulder which Demeter had eaten was made good with one of ivory,761
which was publicly exhibited [pg 264] at Elis down to historical times.762 The
story that one of the members of the mangled Osiris was eaten by fish, and
that, when Isis collected his scattered limbs, she replaced the missing
member with one of wood,763 may perhaps belong to the same circle of
beliefs.

There is a certain rule observed by savage hunters and fishers which,


enigmatical at first sight, may possibly be explained by this savage belief in
resurrection. A traveller in America in the early part of the nineteenth
f century was told by a half-breed Choctaw that the Indians “had an obscure
story, somewhat resembling that of Jacob wrestling with an angel; and that
the full-blooded Indians always separate the sinew which shrank, and that it
is never seen in the venison exposed for sale; he did not know what they
did with it. His elder brother, whom I afterwards met, told me that they eat
it as a rarity; but I have also heard, though on less respectable authority,
that they refrain from it, like the ancient Jews. A gentleman, who had lived
on the Indian frontier, or in the nation, for ten or fifteen years, told me that
he had often been surprised that the Indians always detached this sinew;
but it had never occurred to him to inquire the reason.”764 James Adair, who
knew the Indians of the South-Eastern States intimately, and whose absurd
theories appear not to have distorted his view of the facts, observes that
“when in the woods, the Indians cut a small piece out of the lower part of
the thighs of the deer they kill, lengthways and pretty deep. Among the
great number of venison-hams they bring to our trading-houses, I do not
remember to have observed one without it.... And I have been assured by a
gentleman of character, who is now an inhabitant of South Carolina, and
well acquainted with the customs of the northern Indians, that they also cut
a piece out of the thigh of every deer they kill, and throw it away; and
reckon it such a dangerous pollution to eat it as to occasion sickness and
other misfortunes of sundry kinds, especially by spoiling their guns from
shooting with proper force and direction.”765

[pg 265]

In more recent times the statement of Adair's informant has been confirmed
by a French missionary, who has also published the “obscure story” to which
the English traveller Hodgson refers. The Loucheux and Hare-skin Indians
who roam the bleak steppes and forests that stretch from Hudson's Bay to
the Rocky Mountains, and northward to the frozen sea, are forbidden by
custom to eat the sinew of the legs of animals. To explain this custom they
tell the following “sacred story.” Once upon a time a man found a burrow of
porcupines, and going down into it after the porcupines he lost his way in
the darkness, till a kind giant called “He who sees before and behind”
released him by cleaving open the earth. So the man, whose name was
“Fireless and Homeless,” lived with the kind giant, and the giant hunted
elans and beavers for him, and carried him about in the sheath of his flint
knife. “But know, my son,” said the giant, “that he who uses the sky as his
head is angry with me, and has sworn my destruction. If he slays me the
clouds will be tinged with my blood; they will be red with it, probably.” Then
he gave the man an axe made of the tooth of a gigantic beaver, and went
forth to meet his foe. But from under the ice the man heard a dull muffled
sound. It was a whale which was making this noise because it was naked
and cold. Warned by the man, the giant went toward the whale, which took
human shape, and rushed upon the giant. It was the wicked giant, the kind
giant's enemy. The two struggled together for a long time, till the kind giant
cried, “Oh, my son! cut, cut the sinew of the leg.” The man cut the sinew,
and the wicked giant fell down and was slain. That is why the Indians do
not eat the sinew of the leg. Afterwards, one day the sky suddenly flushed a
fiery red, so Fireless and Homeless knew that the kind giant was no more,
and he wept.766

[pg 266]

This myth, it is almost needless to observe, does not really explain the
custom. People do not usually observe a custom because on a particular
occasion a mythical being is said to have acted in a certain way. But, on the
f contrary, they very often invent myths to explain why they practise certain
customs. Dismissing, therefore, the story of Fireless and Homeless as a
myth invented to explain why the Indians abstain from eating a particular
f sinew, it may be suggested767 that the original reason for observing the
custom was a belief that the sinew in question was necessary to
reproduction, and that deprived of it the slain animals could not come to life
again and stock the steppes and prairies either of the present world or of
the spirit land. We have seen that the resurrection of animals is a common
article of savage faith, and that when the Lapps bury the skeleton of the
male bear in the hope of its resurrection they are careful to bury the genital
parts along with it. However, subsequent enquiries make it probable that the
Indian practice of cutting out the hamstring of deer has no other object than
that of preventing eaters of venison from going lame. Among the Cherokee,
we are told, “on killing a deer the hunter always makes an incision in the
hind quarter and removes the hamstring, because this tendon, when
severed, draws up into the flesh; ergo, any one who should unfortunately
partake of the hamstring would find his limbs drawn up in the same
manner.”768 Thus the superstition [pg 267] seems to rest on the common
principle of homoeopathic or imitative magic, that an eater infects himself
with the qualities of the animal of whose flesh he partakes. Many instances
of the application of that principle have met us already.769

But some hunters hamstring the game for a different purpose; they hope
thereby to prevent the dead beast or its ghost from getting up and running
away. This is the motive alleged for the practice by Koui hunters in Laos;
they think that the spells which they utter in the chase may lose their
magical virtue, and that the slaughtered animal may consequently come to
life again and escape. To prevent that catastrophe they therefore hamstring
the beast as soon as they have butchered it.770 When an Esquimau of Alaska
has killed a fox, he carefully cuts the tendons of all the animal's legs in order
to prevent the ghost from reanimating the body and walking about.771 But
f
hamstringing the carcase is not the only measure which the prudent savage
adopts for the sake of disabling the ghost of his victim. In old days, when
the Aino went out hunting and killed a fox first, they took care to tie its
mouth up tightly in order to prevent the ghost of the animal from sallying
forth and warning its fellows against the approach of the hunter.772 The
Gilyaks of the Amoor River put out the eyes of the seals they have killed,
lest the ghosts of the slain animals should know their slayers and avenge
their death by spoiling the seal-hunt.773 The custom of putting out the eyes
of slaughtered animals appears to be not uncommon among primitive
peoples, and we may suspect that even where a different reason is alleged
for it, the true [pg 268] original motive was to blind the dangerous ghost of
the injured creature, and so to incapacitate it for retaliating on the slayer.
f Thus, when a Samoyed has killed a wild reindeer, one of the first things he
does is to cut out the eyes and throw them away “in order to ensure a good
bag in future”; and he buries the eyes in some place where no woman or
adult girl is likely to step over them, since that also would spoil his luck in
the chase.774 Among the tribes of South-east Africa hunters pluck out the
right eye of any animal they have killed and pour a charmed medicine into
the empty socket.775 Among the Thompson Indians of British Columbia a
man whose daughter has just arrived at puberty may not hunt or trap for a
month, or he will have no luck. Moreover, he should cut off the head of the
first grouse he snares, pluck out the eyes, and insert two small roots of the
Zygadenus elegans Pursch. in the orbits and another in its mouth, and
having done so he ought to hang up the bird's head above his pillow. If he
neglects these precautions, he will not be able to snare any more grouse or
other small game.776 No doubt the ceremonial pollution contracted by his
daughter at this critical period of her life is supposed to infect the hunter
and render him unacceptable to the game;777 hence it seems a mere
elementary dictate of prudence to hoodwink the grouse effectually by
putting out their eyes. Sometimes, perhaps, the cutting out of the eyes of
fierce and powerful animals may be a rational, not a superstitious,
precaution. Thus the Kamtchatkans, who stab with knives the eyes of slain
bears before they cut the carcases up, allege as their reason for doing so
that bears which seem to be dead [pg 269] of their wounds will sometimes
revive and kill their would-be killers.778

It appears to be a common custom with savage hunters to cut out the


tongues of the animals which they kill. On the analogy of the foregoing
customs we may conjecture that the removal of the tongues is sometimes a
f precaution to prevent the ghosts of the creatures from telling their sad fate
to their sympathising comrades, the living animals of the same sort, who
would naturally be frightened, and so keep out of the hunter's way. Thus,
for example, Omaha hunters remove the tongue of a slain buffalo through
an opening made in the animal's throat. The tongues thus removed are
sacred and may not touch any tool or metal except when they are boiling in
the kettles at the sacred tent. They are eaten as sacred food.779 Indian bear-
hunters cut out what they call the bear's little tongue (a fleshy mass under
the real tongue) and keep it for good luck in hunting or burn it to
determine, from its crackling and so on, whether the soul of the slain bear is
angry with them or not.780 In folk-tales the hero commonly cuts out the
tongue of the wild beast which he has slain and preserves it as a token. The
incident serves to shew that the custom was a common one, since folk-tales
reflect with accuracy the customs and beliefs of a primitive age.781 On the
other hand, the [pg 270] tongues of certain animals, as the otter and the
eagle, are torn out and sometimes worn round their necks by Thlinkeet and
Haida shamans as a means of conferring superhuman knowledge and power
on their possessors.782 In particular, an otter's tongue is supposed to convey
a knowledge of “the language of all inanimate objects, of birds, animals,
and other living creatures” to the shaman, who wears it in a little bag hung
round his neck.783 When a Galla priest sacrifices an animal and decides that
the omens are favourable, he cuts out the tongue, sticks his thumb through
it, and so flays the animal.784 In certain cases Gallas cut out the tongues of
oxen and wear them on their heads as tokens.785 In Bohemia a fox's tongue
is worn as an amulet to make a timid person bold;786 in Oldenburg and
Belgium it is a remedy for erysipelas.787 In Bohemia the tongue of a male
snake, if cut from the living animal on St. George's Eve and placed under a
person's tongue, will confer the gift of eloquence.788 The Homeric Greeks cut
out the tongues of sacrificial victims and burned them.789 According to some
accounts, the tongues of the victims were assigned by the Greeks to
Hermes, as the god of speech, or to his human representatives the
heralds.790 [pg 271] On the principles of sympathetic magic we might expect
that heralds should taste the tongues of sacrificial victims to strengthen
their voices, or to acquire the gift of tongues.791

The conjecture that the practice of cutting out the tongues of dead animals
may sometimes be a precaution to prevent their ghosts from telling tales, is
to some extent confirmed by a ceremony which the Bechuanas used to
f observe after a battle. It was customary with them on these occasions to
sacrifice a fine black ox, called the expiatory victim (pekou), cut off the tip
of its tongue, and extract one of its eyes together with a piece of the
hamstring and a piece of the principal tendon of the shoulder; and the
severed parts were afterwards carefully fried, along with some medicinal
herbs, in a horn by a medicine-man. The reasons for thus mutilating the
animal were explained by a native to two French missionaries. “If we cut out
and purify the victim's tongue,” said he, “the motive is to induce the
guardian deities to prevent the enemy from speaking ill of us. We ask also
that the sinews of their feet and hands may fail them in the battle; and that
their eyes may not cast a covetous look on our herds.”792 In this custom the
sacrificial ox appears to be treated as the ceremonial equivalent of the
enemy; accordingly by cutting out its tongue you obviously prevent your
enemy from cursing you, for how can he curse you if he has no tongue?
Similarly, by hamstringing the beast you ensure that the legs and arms of
your adversary will fail him in the battle, and by gouging out the ox's eye
you make perfectly certain that the foe will never be able to cast a longing
eye on your fat beeves. Thus for all practical purposes the mutilation of the
ox is quite as effective as the mutilation of the enemy's dead, which is
sometimes practised by savages from similar superstitious motives. Thus on
the return from a field of battle the Baganda used to cut up one or two of
the enemy's dead, scoop out the eyes, cut off the ears, and lay the limbs on
the road taken by the returning army “to [pg 272] prevent evil following
them.”793 The nature of the evil which the Baganda warriors feared to incur
if they did not mutilate the dead in this fashion, is not mentioned, but we
may conjecture that by gouging out the eyes and ears of their slain foes
they hoped to make their angry ghosts blind and deaf; or perhaps, upon the
principles of homoeopathic magic, they counted on maiming their living foes
in like manner. Some of the aborigines of Australia cut off the thumbs of
their dead enemies in order that their ghosts may not be able to throw
spears.794 Other Australian tribes burn off the thumb nails of their own dead
to prevent the poor ghost from scratching a way for himself out of the
grave.795 When the Tupi Indians of Brazil killed and ate a prisoner, “the
thumb was cut off because of its use in archery, an art concerning which
they were singularly superstitious; what was done with it does not appear,
except that it was not eaten like the rest.”796 Perhaps these Indians, like the
Australians, thought by this mutilation to disarm the dangerous ghost of
their victim. When any bad man died, the Esquimaux of Bering Strait used
to cut the sinews of his arms and legs, “in order to prevent the shade from
returning to the body and causing it to walk at night as a ghoul.”797 In
Travancore the ghosts of men who have been hanged for murder are
particularly dreaded; so in order to incapacitate them from roaming about
and attacking people, it used to be customary to slice off a criminal's heels
with a sword or hamstring him at the moment when he swung free from the
ladder.798 The Omaha Indians used to slit the soles of a man who had been
killed by lightning in order to prevent his ghost from walking.799 Among the
Awemba of [pg 273] Northern Rhodesia murderers often inflicted shocking
mutilations on the bodies of their victims. “This was done, it is said, to
prevent the spirit of the murdered person from exacting vengeance, and
even if only the joint of the first or the little finger were cut off, such
mutilation would suffice for this purpose.”800 These examples suggest that
many other mutilations which savages practise on their dead enemies may
spring, not from the blind fury of hatred, but from a cool calculation of the
best mode of protecting themselves against the very natural resentment of
the ghosts; by mutilating the corpse they apparently hope to maim the
ghost and so to render him incapable of harming them. At all events it
appears that in certain circumstances some savages treat the dead bodies of
men and beasts much alike, by hamstringing them in order to prevent their
ghosts from getting up and walking. So consistent and impartial is the
primitive philosopher in his attitude to the spirit world.

[pg 274]
Chapter XV. The Propitiation of Vermin by
Farmers.
§ 1. The Enemies of the Crops.

Besides the animals which primitive man dreads for their strength and
ferocity, and those which he reveres on account of the benefits which he
expects from them, there is another class of creatures which he sometimes
deems it necessary to conciliate by worship and sacrifice. These are the
vermin that infest his crops and his cattle. To rid himself of these deadly
foes the farmer has recourse to many superstitious devices, of which,
though some are meant to destroy or intimidate the vermin, others aim at
propitiating them and persuading them by fair means to spare the fruits of
the earth and the herds. Thus Esthonian peasants, in the island of Oesel,
stand in great awe of the weevil, an insect which is exceedingly destructive
to the grain. They give it a fine name, and if a child is about to kill a weevil
they say, “Don't do it; the more we hurt him, the more he hurts us.” If they
find a weevil they bury it in the earth instead of killing it. Some even put the
weevil under a stone in the field and offer corn to it. They think that thus it
is appeased and does less harm.801 Amongst the Saxons of Transylvania, in
order to keep sparrows from the corn, the sower begins by throwing the
first handful of seed backwards over his head, saying, “That is for you,
sparrows.” To guard the corn against the attacks of leaf-flies (Erdflöhe) he
shuts his eyes and scatters three handfuls of oats in different directions.
Having made this offering to the leaf-flies he feels sure that [pg 275] they
will spare the corn. A Transylvanian way of securing the crops against all
birds, beasts, and insects, is this: after he has finished sowing, the sower
goes once more from end to end of the field imitating the gesture of
sowing, but with an empty hand. As he does so he says, “I sow this for the
animals; I sow it for everything that flies and creeps, that walks and stands,
that sings and springs, in the name of God the Father, etc.”802 The Huzuls of
the Carpathians believe that the bite of the weasel is poisonous and that the
animal commits ravages on the cattle. Yet they take care never to kill a
weasel, lest the surviving kinsfolk of the deceased should avenge his death
on the herds of his murderer. They even celebrate a festival of weasels
either on St. Matthew's day (9th August, old style, 21st August, new style),
or on St. Catherine's day (24th November, old style, 6th December, new
style). On that day no work may be done, lest the weasels should harm the
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like